Swift iOS重置ViewController层次结构 [英] Swift ios reset viewcontroller hierarchy
问题描述
在情节提要中,我的应用程序设计为:
In storyboard my app is designed as:
导航VC-> VC1
Navigation VC -> VC1
我要执行的操作是锁定到另一个VC,但是重置菜单层次结构,以便我不要将旧的VC堆叠在背景中
What I am trying to do is to segue to another VC but reset the menu-hierarchy so that i dont have the old VC's stacked in the backgound
我想做的是:
导航VC-> VC1-> VC2-> 已重置导航的新VC
Navigation VC -> VC1 -> VC2 -> NEW VC with Navigation reseted
因此,当用户登录并进入VC/Page帐户时,在击中VC/Page帐户时应重置导航堆栈
So when a user logs in and enters the account VC/Page the navigation stack should be resetted when hitting the account VC/Page
这可能吗?
推荐答案
如果您不想将视图控制器添加到导航控制器中,则导航到的每个View控制器都可以将其设置为导航的根视图控制器控制器,它不会添加到您的堆栈中.
If you do not want to add the view controllers to your navigation controller, every View controller you navigate to you can set that as the root view controller of your navigation controller and it won't be added in your stack.
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController
let navigationController = self.view.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewController], animated: true)
这篇关于Swift iOS重置ViewController层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!