Mark Löwe
Mark Löwe

Reputation: 582

Swift: performSegueWithIdentifier during unwind not working

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

Upvotes: 1

Views: 3441

Answers (2)

Pradeep K
Pradeep K

Reputation: 3661

  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.

Upvotes: 1

Paulw11
Paulw11

Reputation: 114846

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)

Upvotes: 1

Related Questions