简体   繁体   中英

how to unwind segue to the view controller that called it

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?

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

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