How to segue to one view controller from multiple

2019-09-08 18:28发布

enter image description here

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.

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.

Thanks

2条回答
迷人小祖宗
2楼-- · 2019-09-08 18:56

You just need to call popViewController to dissmiss viewcontroller. It will automatically follow navigation stack which was created by navigationcontroller A or B.

If you want to pop to first viewcontroler then can call popToRootViewController.

Hope this will help :)

查看更多
Fickle 薄情
3楼-- · 2019-09-08 19:14

Just set storyboard ID's for the navigation controllers, Once you reach the final view controller. Just use:

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

use prepareForSegue to get to NavigationViewController you want

Set a Bool value and pass it along from Navigation view controllers, while traversing to the last view controller. 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 :

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

查看更多
登录 后发表回答