在故事板中,我的应用程序设计为:
导航VC - > VC1
我想要做的是切换到另一个VC,但重置菜单层次结构,以便我不将旧VC堆叠在背景中
我想做的是:
导航VC - > VC1 - > VC2 - > 新VC导航已重置
因此,当用户登录并输入帐户VC / Page时,应该在点击VC / Page
帐户时重置导航堆栈这可能吗?
答案 0 :(得分:4)
如果您不想将视图控制器添加到导航控制器,则导航到您的每个View控制器都可以将其设置为导航控制器的根视图控制器,并且不会将其添加到堆栈中。
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)
答案 1 :(得分:0)
我的解决方案与上述相同但只有一行
let yourViewControllerObejct = self.storyboard?.instantiateViewControllerWithIdentifier("YourViewControllerId") as? YourViewController
let navigationController = self.view.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([yourViewControllerObejct!], animated: true)