Azul Azul - 1 month ago 10
iOS Question

When is shouldPerformSegueWithIdentifier called?

I created a segue from a button (ctrl-drag) from one scene to another in the storyboard. I also created an IBAction connected to the same button. In the View controller where I implemented the IBAction I also implemented shouldPerformSegueWithIdentifier.

When I run it shouldPerformSegueWithIdentifier is called first and second the IBAction.

However, I have an old project with the same setup where the IBAction is called before shouldPerformSegueWithIdentifier.

Is there a specific order these two methods are called? Is there any way to change that order?

In another similar post the answer suggests to call shouldPerformSegueWithIdentifier from the IBAction. Is that a good practice?

Thanks.

Answer

When I run it shouldPerformSegueWithIdentifier is called first and second the IBAction

Only one of them should be called — the IBAction. The fact that they are both called means that your storyboard configuration is incorrect (in both cases).