我想从顶视图控制器重新初始化我的应用程序。我希望我的应用程序从头开始重新加载视图。
我在applicationWillEnterForeground
方法中试过这个:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
ActivityController *destViewController = (ActivityController *)[storyboard instantiateViewControllerWithIdentifier:@"ActivityView"];
[self.navigationController pushViewController:destViewController animated:YES];
但它没有用。
答案 0 :(得分:0)
如果您不希望自己的应用在后台运行,可以在应用的UIApplicationExitsOnSuspend
true
设置为Info.plist
答案 1 :(得分:0)
applicationDidEnterBackground和applicationWillEnterForeground,
PrintWriter out = new PrintWriter("filename.txt", "UTF-8");
json = json.replaceFirst("^\uFEFF", "");
并在你的rootViewController的viewDidLoad(它总是出现在应用程序启动时)添加:
[[NSNotificationCenter defaultCenter] postNotificationName:@"popToRoot" object:nil];
然后在rootViewController中创建一个方法:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popToRootViewControllerAnimated) name:@"popToRoot" object:nil];
您应该使用- (void)popToRootViewControllerAnimated
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
代替[self.navigationController popToViewController:ActivityController animated:NO];
。
有关详细信息,请参阅this answer。