Search code examples
iosswiftuiviewcontrolleruistoryboardsegue

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


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


Solution

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