Help Dismissing View Controller in Modally Segue

I am creating an app that opens with ViewController1, then a button opens another view contoller (ViewController2) with a modally segue. Then ViewController2 has a button that opens another view controller (ViewController3) using another modally segue. Both 2 and 3 view contollers have a dismiss button that dismisses the view controller.


The problem is that whenever ViewController3 uses the dismiss button, it dismisses to ViewController 2 when I want it to dismiss to ViewController1. I've tried using the dismiss action to dismiss ViewController2 one the button is pressed, but then the segue doesn't get committed.

This may be confusing so please ask questions if you need help understanding. Thanks so much in advace!


(I am using Swift 3 and Xcode 8)

Accepted Reply

Thanks to some help by goldsdad, I got an answer! Here's how you do it:


On ViewController 1, add this following code:


@IBAction func homeUndwind(segue: UIStoryboardSegue) {
    }


Then on ViewControllers 2 and 3, on the dismiss button (via the storyboard) drag from the button to the Exit button at the top of the storyboard.



And, that's it! Thanks for all the help!

Replies

Maybe these will help:

h ttps://spin.atomicobject.com/2015/04/23/unwind-segue-set-destination/

https://developer.apple.com/library/content/technotes/tn2298/_index.html#//apple_ref/doc/uid/DTS40013591-CH1-DETDEST

Thanks to some help by goldsdad, I got an answer! Here's how you do it:


On ViewController 1, add this following code:


@IBAction func homeUndwind(segue: UIStoryboardSegue) {
    }


Then on ViewControllers 2 and 3, on the dismiss button (via the storyboard) drag from the button to the Exit button at the top of the storyboard.



And, that's it! Thanks for all the help!