[英]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.