简体   繁体   English

如何从多个导航控制器中选择一个视图控制器,完成后如何快速返回显示的任何一个视图控制器

[英]How to segue to one view controller from multiple navigation controllers and when done go back to whichever view controller presented it swift

在此处输入图片说明

So I have two navigation controller hierarchies that both lead to one view controller. 因此,我有两个导航控制器层次结构,它们都导致一个视图控制器。 I pass that one view controller data based on which one presented it with a push segue. 我传递了一个视图控制器数据,基于该数据以推送方式呈现给它。 How do I dismiss the final view controller and go back to the navigation stack that presented it? 如何关闭最终视图控制器并返回显示它的导航堆栈? I don't need to pass any info back, but when I tried to do an unwind segue I was getting an error stating "this class is not key value coding-compliant for the key doneButtonTapped" I tried unWind segue and popVC segue. 我不需要传递任何信息,但是当我尝试进行结束搜索时,我收到一条错误消息,指出“该类与键doneButtonTapped的键值编码不兼容”,我尝试了取消WinWin和popVC segue。

I believe the problem might be that you can't have two separated navigation stacks leading to one view controller because that view controller doesn't know which stack it is a part of. 我认为问题可能是您不能有两个单独的导航堆栈通向一个视图控制器,因为该视图控制器不知道它属于哪个堆栈。 I tried researching but could only find how to dismiss multiple modal views at once, nothing about dismissing one VC to which ever VC presented it at the time. 我尝试研究,但是只能找到如何一次消除多个模式视图的方法,与解散当时由VC提出的一个VC无关。

Thanks 谢谢

You just need to call popViewController to dissmiss viewcontroller. 您只需要调用popViewController即可popViewController viewcontroller。 It will automatically follow navigation stack which was created by navigationcontroller A or B. 它会自动跟随由导航控制器A或B创建的导航堆栈。

If you want to pop to first viewcontroler then can call popToRootViewController . 如果要弹出到第一个viewcontroler,则可以调用popToRootViewController

Hope this will help :) 希望这会有所帮助:)

Just set storyboard ID's for the navigation controllers, Once you reach the final view controller. 只需为导航控制器设置情节提要ID,一旦到达最终视图控制器即可。 Just use: 只需使用:

self.performSegueWithIdentifier(identifier: String, sender: AnyObject?)

use prepareForSegue to get to NavigationViewController you want 使用prepareForSegue转到所需的NavigationViewController

Set a Bool value and pass it along from Navigation view controllers, while traversing to the last view controller. 设置一个Bool值并将其从“导航”视图控制器传递出去,同时遍历到最后一个视图控制器。 For example, pass true when going from Nav A, and pass false when going from Nav B. Once you get to the final ViewController, use this boolean value : 例如,从Nav A转到时传递true,从Nav B转到时传递false。一旦到达最终的ViewController,请使用以下布尔值:

if boolValue == true {
self.performSegueWithIdentifier(identifier: "identifierforNavA", sender: AnyObject?)
}
else {
self.performSegueWithIdentifier(identifier: "identifierforNavB", sender: AnyObject?)
}

Don't forget to implement prepareForSegue for performSegueWihIdentifier to work 不要忘了实现prepareForSegue以便performSegueWihIdentifier起作用

暂无
暂无

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

相关问题 Swift:如何在视图控制器之间进行切换,并使用导航栏在子视图控制器中向后移动(XLPagerTabStrip) - Swift: How to segue between view controllers and use navigation bar to go backwards within a child view controller (XLPagerTabStrip) 您可以从多个导航控制器中选择一个情节提要视图控制器吗? - Can you segue to a storyboard view controller from multiple navigation controllers? Swift:在XLPagerTabStrip中使用子视图控制器后,如何选择回到第一个视图控制器 - Swift: How to segue back to first view controller after using child view controllers from the XLPagerTabStrip 从一个视图控制器中选择到不同的控制器 - Segue to different controllers from one view controller 如何使用导航控制器设置(包括后退设置)显示视图控制器(快速) - How to show a view controller using a navigation controller segue, including back segue (Swift) 从导航控制器到视图控制器的Swift自定义展开Segue - Swift custom unwind Segue from Navigation controller to View Controller 呈现视图中的导航控制器 - Navigation Controller in presented view 如何从根视图控制器到导航堆栈中的最后一个视图控制器快速执行segue? - how to perform segue from root view controller to the last view controller in the navigation stack in swift? 是否可以快速从模态视图选择到导航控制器上不在层次结构中的视图? - Is it possible to segue from a modal view to a view that is not in the hierarchy on a Navigation Controller in swift? 如何将引用从调用视图控制器传递给呈现有segue的引用? - How do I pass a reference from a calling view controller to one presented with a segue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM