0

I'm trying to get an unwind segue working (in Swift) and have read through all the "unwind segue not working" posts I could find but haven't yet found whatever it is I'm doing wrong. So.

I have a UISplitViewController with a UITableViewController as my left-hand menu and two UINavigationController+UITableViewController detail views that I'm switching between. Segue-based navigation from my left-hand menu works fine. It's when I want to programmatically unwind that things do not.

I've created an @IBAction function in my first view controller, the one I want to unwind to, like this:

@IBAction func unwindToDocuments(_ segue: UIStoryboardSegue) {
}

(My first view controller is my "Documents" view.)

Then, in the second view controller, I connect an unwind segue to the exit node with identifier unwindSegueToDocuments and action unwindToDocumentsWithSegue:.

It's my understanding that should be all I need to do. However, when I try:

self.performSegue(withIdentifier: "unwindSegueToDocuments", sender: self)

it doesn't do anything. It stays in my second view controller as the detail view.

I'm using self.performSegue there because I'm in a closure. It's some network work so it's being done in a DispatchQueue.async() background queue. However, the performSegue call is in a nested DispatchQueue.main.async() block at the end. (Or, rather, I've tried it both/all ways, and still can't get it to unwind.)

Nothing helpful appears in the console.

KT_
  • 978
  • 11
  • 26
  • 1
    Is your action really `unwindToDocumentsWithSegue:`? If so, then you need to remove that `_` in `unwindToDocuments(_ segue: UIStoryboardSegue)`. – vacawama Dec 09 '17 at 17:43
  • Ah, I based that on the recommendation to add it in https://stackoverflow.com/questions/39915867/unwind-segue-doesnt-work-in-swift-3-and-ios-10, which apparently worked. What's more surprising to me is that there's no issue reported at either compiler or runtime with/without it. Normally Swift is a lot pickier about syntax. Anyway, removing it makes no difference. – KT_ Dec 09 '17 at 22:43
  • Alternatively, you can leave the `_` and your action is then just `unwindToDocuments:`. They just have to match. – vacawama Dec 09 '17 at 23:16
  • Makes sense. Anyway, I've gone back to ```@IBAction func unwindToDocuments(segue: UIStoryboardSegue)``` and action ```unwindToDocumentsWithSegue:```. Unfortunately it still doesn't work. – KT_ Dec 09 '17 at 23:21
  • I'm still having a little trouble understanding your setup. What kind of segue are you using to move between the right detail views. What exactly are you unwinding? Could you describe how the user will interact with your app? – vacawama Dec 09 '17 at 23:33
  • Well, for instance, I've drawn a segue from each cell on my (left) menu table view in the ```UISplitView``` to the relevant detail view for that action. They work fine without any additional coding. It's when I complete an action in my second view controller that I want to "pop" back to the first/root/main Documents view controller. Basically I want to mimic tapping on the Documents menu item (cell) in my left-hand menu, which works fine. So if Documents is the first detail view, and I navigate by tapping to my second detail view, I want to unwind programmatically back to my Documents view. – KT_ Dec 09 '17 at 23:38
  • If I'm not mistaken, the segues that you have used are doing a *Replace*. In other words, they create the new detail view, switch to it and then release the first one. So, I don't think there is anything to unwind *to*. – vacawama Dec 09 '17 at 23:45
  • Perhaps you can send a message back to the "menu" VC and have it segue to the Documents view. – vacawama Dec 09 '17 at 23:59
  • Thank you for the clarification. Seems like I may have come full circle, then, since the unwind segue was the solution I came across to a previous problem where manually swapping the detail view wasn't allowing a segue from my main menu tableview to work a second time. Back to that problem, I guess. Thanks again. – KT_ Dec 10 '17 at 03:00

0 Answers0