简体   繁体   English

在没有NavigationController的情况下展开到特定的ViewController

[英]Unwind To Specific ViewController Without NavigationController

I am trying to unwind to a specific viewController without using navigationController. 我试图在不使用navigationController的情况下展开到特定的viewController。 For instance, I have a set of questions the user needs to answer. 例如,我有一系列用户需要回答的问题。 Depending on their answer they either need to get unwound to the root controller or the first question. 根据他们的答案,他们要么需要解开根控制器,要么是第一个问题。 I am aware of how I would go about navigating them to the root controller, I just don't know how to go back to any other specific controller. 我知道如何将它们导航到根控制器,我只是不知道如何返回到任何其他特定控制器。 I am under the understanding that if I were to use a segue to go from viewController 4 -> 2 it would use more memory and the stack could end up like 1->2->3->4->2 etc... 我的理解是,如果我要使用segue从viewController 4-> 2进入,它将使用更多的内存,并且堆栈最终可能像1-> 2-> 3-> 4-> 2等...

Any suggestions would be greatly appreciated. 任何建议将不胜感激。

You can use something like the following method to pop as many views at a time as you need. 您可以使用以下方法来一次弹出所需的视图。

+ (void)popBackWithSourceViewController:(UIViewController *)viewController viewsToPop:(int) viewsToPop {            
    [viewController.navigationController popToViewController:viewController.navigationController.viewControllers[viewController.navigationController.viewControllers.count-viewsToPop-1];
}

In each VC you want to unwind to you need to create an @IBAction func with one argument (_ segue UIStoryboardSegue) then in Your storyboard you go to the vc you want to unwind from and on the top control click drag between th VC icon and the exitnicon. 在每个要解散的VC中,需要创建一个带有一个参数的@IBAction函数(_ segue UIStoryboardSegue),然后在情节提要中转到要解散的vc,并在顶部控件上单击VC图标和出口。 You need to choose the unwind function and then a new segue appears in your VC tree on the left hand side. 您需要选择展开功能,然后新的序列会出现在左侧VC树中。 Clicking on the segue gives you an option as with regular soryboard segues togive it an ID. 单击该序列可以为您提供一个选项,就像使用常规soryboard序列将其作为ID一样。 Once named you can programatically perform segue with identifier. 命名后,您可以以编程方式执行带有标识符的segue。 You can add as many of these segues as you like. 您可以根据需要添加任意多个Segue。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM