blutie blutie - 9 months ago 53
Swift Question

Why is interface builder not showing my unwind segue?

My app's navigation flow looks a bit like this:

UINavigationController - MasterViewController > DetailViewController > InfoViewController

MasterViewController contains the following method:

@IBAction func unwindToMaster(with segue: UIStoryboardSegue) {}


In DetailViewController, there is a similar method:

@IBAction func unwindToDetail(with segue: UIStoryboardSegue) {}


I use these methods, along with UIButtons, to allow the user to advance forward and back through the navigation hierarchy. In interface builder, I see the method under DetailViewController when I right click on "Exit" in InfoViewController, but when I right click on "Exit" in DetailViewController, no other unwind segues are listed.

I have consulted multiple online sources (Ray Wenderlich, relevant StackOverflow questions) instructing the correct way to produce unwind segues in interface builder, but none of these have helped solve the issue. Right now, I need help figuring out what the problem is in the first place. As development usually goes, it's probably something staring me square in the face.

Exit Menu in DetailViewController — 'unwindToPersonWith:' = 'unwindToDetail'

I am running Xcode 8.1 using Swift 3. Thank you.

Answer Source

To re-iterate: not only an Action for a Storyboard Unwind Segue has to be placed in the same source file as class definition for an unwind-to (destination) View Controller (e.g., @IBAction func prepareForUnwind(segue: UIStoryboardSegue), detected as prepareForUnwind[With]Segue in a "Presenting Segues" list), but also that View Controller cannot have ANY extensions in ANY secondary source files. You have to merge class definition and all extensions into a single source file.

(As of Xcode 8.2.1.)