简体   繁体   中英

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.

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

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 :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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