Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 795
blutie Avatar asked Oct 30 '16 01:10

blutie


2 Answers

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

like image 191
Gary Avatar answered Oct 04 '22 20:10

Gary


In my case, I had a complicated inheritance in my view controller and it was a reason why Interface Builder did not see my unwind. So this workaround works for me well:

  1. Go to YouCollViewController.swift file and delete all classes, protocols, generics, etc. your view controller implements in view controller's declaration
  2. Inherit your view controller from UIViewController
  3. Go to the storyboard and connect your action with the unwind, it should appear in unwinds list
  4. Go back to YouCollViewController.swift file and discard all the changes
like image 38
Rostyslav Druzhchenko Avatar answered Oct 04 '22 19:10

Rostyslav Druzhchenko