1
votes

I've created a typical unwind flow from my view controller #2 to back to view controller #1 using a programmatically created button using the segue to Exit technique.

I have trace statements that confirm that the button code is executing perfectly and that the #2 performSegueWithIdentifier func is being called with the correct segue ID, but nothing happens.

To clarify:

I've connect the view controller #2 to the Exit and confirmed the segue ID is exact in all places. I traced the #2 identifier in the #2 performSegueWithIdentifier func and it matches perfectly.

As I understand it, I no longer need to use the dispatch fix with the current version of 2016 XCode. I tried it anyway and nothing worked. There is no crash, just no unwinding.

Somehow the unwind technique isn't reversing using this Exit technique. Any ideas?

I've been following the tutorial here: https://spin.atomicobject.com/2014/12/01/program-ios-unwind-segue/

CODE VC #2:

// action func wired to button, fires perfectly
func unwind(seg:UIStoryboardSegue!) {

    self.performSegueWithIdentifier("unwind", sender: self)
}
2
Can you show the code you have in vc1 and the code in vc2?Paulw11
Not much to it. Both the above functions fire perfectly and trace out print statements with the exact segue names I've used. :( The only code in the V2 is the viewDidLoad function that doesn't fire at all.Mark Löwe
you don't implement performSegueWithIdentifier; this is implemented by UIViewController. The IBActionMethod with a UIstoryboardSegue argument should be in VC1 (it has an empty implementation). You call self.performSegueWithIdentifier in the button handler method which if you aren't using a storyboard doesn't need to have @IBActionPaulw11
Ok, I tried as much of that as I understood and now it throws tons of errors, due to the lack of recognition of the segue assignments to the VCs. As I understand the unwind method is that I'm queuing a segue to the Exit of vc2 to simply "leave" the stage, thus returning the next VC in the stack which is VC1. I only used the performSegueWithIdentifier in VC2 to trace out the segue name. I removed the IBAction prefix.Mark Löwe
Have demo with unwind segue,Kirit Modi

2 Answers

1
votes

In VC1 you need a function:

@IBAction func unwindToVC1(segue:UIStoryboardSegue) {
}

Then in your storyboard ctrl drag from the yellow view controller icon to the Exit icon and select unwindToVC1: from the pop up

Give the unwind segue an identifier, say unwindToVC1

Now, in VC2, create your button touchUpInside handler:

func buttonTapped(sender:UIButton) {
    self.performSegueWithIdentifier("unwindToVC1")
}

when you set up your button programatically, add this method as the action handler:

button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
1
votes
  1. Move the unwind function to VC1. Leave that implementation empty or perhaps put a print statement to see if its coming to that function.
  2. Make sure that in the storyboard there is a unwind segue created with identifier "unwind"
  3. Add a button action func buttonAction:(button:UIButton) that calls performSegueWithIdentifier("unwind"...) in VC2.
  4. Set the buttonAction as the action for the button created programatically.