clicky
clicky

Reputation: 865

Segue prepared but performance fails without exception

I have two views, A and B with a modal segue between them. The controller of A has @IBAction func unwindSegue(segue: UIStoryboardSegue) defined.

I am trying to perform the unwind segue (back from view B to A) programatically which fails without producing any error. In the controller for view B I call performSegueWithIdentifier("unwind", sender: self) and can see that func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) is called but after that nothing happens.

I have given the custom name to the unwind segue in XCode and have the same setup between view B and C (with a different name to avoid conflicts) which works correctly.

Edit: The unwind is triggered either by a button or code and the button flow works fine. I am confused because the runtime can identify the segue otherwise it would throw an exception - so what could be preventing it from running? I have stepped through the prepare method and nothing is blocking there.

Edit 2: I have noticed that the difference between triggering the unwindSegue between views A and B from the button and via code is the destination VC. When going via the button the destination is view A but via code it is C. Why would this happen? The code flow is triggered via view C, where there is a button to return to view A and is just a series of unwind segues popping views off the stack.

enter image description here

I am able to unwind from each view backwards one at a time via buttons, but if i hit the button to return to view A from views C or D I unwind to view B then encounter the issue where the destination is incorrect and so cannot complete the traversal to view A.

Upvotes: 4

Views: 158

Answers (1)

clicky
clicky

Reputation: 865

Found the answer here https://spin.atomicobject.com/2015/04/23/unwind-segue-set-destination/ and How to unwind through multiple views without displaying intermediate views

I had to add, to vc B, the following as the unwind from view B to A was choosing the wrong 'nearest unwind'.

override func canPerformUnwindSegueAction(action: Selector, fromViewController: UIViewController, withSender sender: AnyObject) -> Bool {
    return fromViewController is ViewC
}

Now a segue will only unwind to view B as the destination if the sender is view C.

Upvotes: 1

Related Questions