4

I can't get unwind segue to work with the latest Xcode 8.1 GM. I'm just wondering if I'm the only one, or someone else is experiencing the same. I have set up the view-controllers as before, it worked in Xcode 8.0, but now I'm having no luck. Tried to clean and so on, but nothing helps. I would like someone else could test it as well before I file a radar...

The view controller that first instantiated the view controller is having the following code:

@IBAction func unwindToSettingsTableViewController(_ segue: UIStoryboardSegue) {
    print("unwind")
}

I also tried without the underscore, but that did not help. When setting up this, one should be able to ctrl drag from files owner to exit, and get up the unwind segues: No unwind segue showing up here... So either am I doing it completely wrong (I dont think so, it worked perfectly fine before), or there is a bug in Xcode 8.1

I tried to do the same in a new project, and then it worked properly. So I guess there is something wrong with my project or storyboard file.

Update

Since the storyboards are holding rather small scenes, I just deleted it, and recreated it again, using the same classes for the view controllers and so on. And now it works. So having exactly the same code, but a fresh storyboard, makes me think it is some bug.

GJ Nilsen
  • 685
  • 8
  • 26
  • If you read the question, you would have seen that I did drag from the files owner and to exit, same is shown in the screenshot. And you are really wrong regarding adding the view programmatically. It works just fine when connecting it up from storyboard. – GJ Nilsen Oct 26 '16 at 17:19

3 Answers3

3

I found the reason for the weird behaviour. It needs a little explanation on how we build our apps to understand the hows and whys.

First of all, instead of having big ViewControllers, we tend to split them into smaller chunks. This way, we always know where the "business logic" is, where to find the data source, outlets and actions, and so on. A typical TableViewController is made like this:

SampleTVC.swift

class SampleTableViewController: UITableViewController {
    @IBOutlet var someLabel: UILabel!
    @IBOutlet var someButton: UIButton!

    @IBAction func unwindHere(_ segue: UIStoryBoardSegue) {
        doSomething()
    }

}

SampleDelegate+DataSource.swift

extension SampleTableViewController {
    override func numberOfSections(in tableView: UITableView) -> Int
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
}

SampleFetchedResultsController.swift

extension SampleTableViewController: NSFetchedResultsControllerDelegate {
    var fetchedResultsController: NSFetchedResultsController<Item>
    func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>)
    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType)
    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?)
    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>)
}

I tried here to connect up the code with a TVC made up of these smaller bits, and no way, no rewind segue pops up.

So, putting all the extensions in the same file as the SampleTableViewController, it would still not work.

The solution was to remove all the extensions, and put all functions into the class itself, then it worked as it should. It does not make much sense, it's clearly a bug.

GJ Nilsen
  • 685
  • 8
  • 26
  • For me, just moving the extensions back to the same file fixed the problem. Clearly a horrible bug. Hopefully fixed soon. – Pat Niemeyer Nov 01 '16 at 18:07
  • I stopped using segues at all, instead I went for the Flow Coordinator model explained by Chris Eidhof and Florian Kugler in Objc.io Swift Talk episode 5. https://talk.objc.io/episodes/S01E05-connecting-view-controllers – GJ Nilsen Mar 01 '17 at 19:09
  • @GJNilsen, this stupid bug still exist in xCode 8.3.3!!..I was having the same issues and started from scratch multiple times only to find out moving the extension classes within the class itself finally allowed me to do an unwind segue via Ctrl+Dragging to Exit...this is really annoying – Pangu Jul 20 '17 at 19:09
1

The same thing happened to me this morning. My problem was that the @IBAction I was creating, got translated into the Storyboard with a different name, which in your case will be:

"unwindToSettingsTableViewControllerWithSegue"

enter image description here

What I did was delete the "WithSegue" part in the Attribute inspector and everything worked as expected. I don't know if this is a bug, or if it is what is happening to you.

Hope it helps.

Diogo Antunes
  • 1,943
  • 1
  • 18
  • 37
  • Thanks for the tip. It did not help me much, but at least I know Im not the only having to fight Storyboards. – GJ Nilsen Oct 26 '16 at 14:28
0

I am having the same issue with my project - but it seems to be a project wide bug.

I can create a new project and have no problems creating an unwind segue, but even creating a new storyboard in my current project with only the NavigationController and two ViewControllers the rewind segue doesn't show up on the exit button.

This is a very annoying bug because it has brought my project to a screeching halt.

Jim Hessin
  • 71
  • 6