如何呈现一个View Controller并解散所有其他控制器? [英] How do I present a View Controller and dismiss all others?
问题描述
我大约有20个View Controller,它们与Modal和Push segues链接在一起.现在,在最后一个View Controller上,我想再次切换回第一个View Controller,就好像用户已重新启动该应用程序一样.不幸的是,当我用
[UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InitViewController"]];
[self presentViewController:viewController animated:YES completion:nil];
所有先前的视图控制器均未卸载.没有调用单个viewDidUnload方法.该怎么办?
我发现通过在层次结构中的第一个视图控制器上调用dismissViewControllerAnimated:completion:可以很容易地做到这一点.幸运的是,这就是完成我想要的一切所需要的:-)I have about 20 View Controllers, chained together with Modal and Push segues. Now, at the last View Controller I want to switch back again to the first View Controller, as if the user has restarted the app. Unfortunately when I do this with
[UIViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InitViewController"]];
[self presentViewController:viewController animated:YES completion:nil];
all of the previous view controllers are not unloaded. Not a single viewDidUnload method is called. How can this be done?
I found that it can be done easily by calling dismissViewControllerAnimated:completion: on the first view controller in the hierarchy. Fortunately that's all it is needed to accomplish what I wanted :-)
这篇关于如何呈现一个View Controller并解散所有其他控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!