I am trying to code a hangman game and am having trouble with unwind segues. I have multiple view controllers that all ultimately lead to the same view, where the user plays
If you have any custom logic and want to invoke the unwind segue programmatically to different view controllers, here is how:
Add unwindFromCViewController
to both BViewController
and DBViewController
:
BViewController.swift
class BViewController : UIViewController {
@IBAction func unwindFromCViewController(segue:UIStoryboardSegue) {
}
}
DViewController.swift
class DViewController : UIViewController {
@IBAction func unwindFromCViewController(segue:UIStoryboardSegue) {
}
}
In your storyboard, create this segue and give it a identifier, and link it to the action you defined above unwindFromCViewController
:
Invoke the unwind segue from code:
self.performSegueWithIdentifier("unwindFromCViewControllerSugueId", sender: self)
With that, you can unwind to a previous view regardless where it is coming from.