0

Below is a great answer of how to use Apple's unwind segue.

What are Unwind segues for and how do you use them?

My problem with the answer however is that you have to explicitly tell storyboard which view controller you want to exit (unwind) back to. What I'm trying to do is exit (unwind) back to whichever view controller called it, only using one button.

Let's say I have 3 view controllers: Red, Blue, and Yellow. Both Red and Blue have a button on them to go to the Yellow view controller, but Yellow only has one button, return. Is it possible to have the yellow return button unwind back to whichever view controller called it?

Community
  • 1
  • 1
amallard
  • 1,189
  • 1
  • 12
  • 24
  • There is a nice tutorial about unwind segue and how to connect them: http://www.raywenderlich.com/113394/storyboards-tutorial-in-ios-9-part-2 – Florian Blum Jan 07 '16 at 18:54
  • 2
    Yes, but probably not using Unwind segues. You could simply add a button that dismisses / pops your current view from the stack. – luk2302 Jan 07 '16 at 18:54

1 Answers1

2

thanks to @luk2302 I was able to figure it out. No need to even use unwind segue. Thanks luk2302!

@IBAction func returnViewController(sender: AnyObject) {
    if((self.presentingViewController) != nil){
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}
amallard
  • 1,189
  • 1
  • 12
  • 24