I have a view controller (in a navigation controller) A that segues to View Controller B, and View Controller C also segues to B (A -> B <- C). View Controller B is used to select a value that is passed back to either A or C, but if I click 'Cancel' or 'Done' it uses the unwind segue to go back to only one controller, whichever was connected last.
Asked
Active
Viewed 383 times
1
-
Did you implement two different unwind segues for controllers A and C? – Richard Mazkewich Dec 16 '15 at 08:21
-
Aaron could you provide more details? Maybe screenshots or code. It's difficult to understand what you want. – Laura Calinoiu Dec 16 '15 at 09:06
1 Answers
8
You can have an unwind segue return to whichever viewController initiated the segue. All you have to do is to implement the same method you are returning to in all of the viewControllers which segue to viewController B.
So in viewController A and viewController C, implement the following method:
@IBAction func backFromB(segue: UIStoryboardSegue) {
print("Back from B")
}
Then, when you Control-drag from your Cancel button in viewController B to the Exit icon at the top of the viewController, select backFromB
from the pop-up.
Then when you run the app and hit Cancel in viewController B, you will return to either viewController A or viewController C (whichever one segued to B). This even works if one segue is a Show (Push) and the other is Modal.

vacawama
- 150,663
- 30
- 266
- 294