0

I made a segue in order to pass data. When i click the button, it does the segue. I want to manage it manually with code, for example i want an error alert to be shown, before it moves into the next view controller. I use the code below, but when i tap the button, it presents the next controller right after.

I tried this:

performSegueWithIdentifier("mysegue", sender: nil)
  • 1
    You need to remove the segue from the button and connect it to the view controller and then use a standard "touch up inside" action handler with the button – Paulw11 Jul 30 '16 at 11:43
  • Another way is via `shouldPerformSegueWithIdentifier`, where you can prevent the segue being performed and do other stuff. This way you can leave the segue on the button but just control it from your code. See http://stackoverflow.com/a/12818366/2350304 – Juul Jul 30 '16 at 16:55

1 Answers1

0

You can't create a segue programmatically. You can invoke one programmatically however. As Paul says, remove the segue from your button and control-drag a segue from the source view controller to the destination you controller. Give it a unique identifier. Then you can invoke the segue in code with a call to performSegueWithIdentifier

Duncan C
  • 128,072
  • 22
  • 173
  • 272