I have two view controllers. On view controller1 I have the following:
In my code I have the following for the button press action
@IBAction func buttonPress(sender: AnyObject) { println("button pressed") performSegueWithIdentifier("showme", sender: self) }
I also have the following method:
override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool { println("Should performing....") return true }
For some reason the shouldPerformSegueWithIdentifier function is never called. If however, I add the segue directly on the UIButton to ViewController2 it is.
I have confirmed that calling it direction within my button action works (see below), but this is not what I understand to be the way it works. The same is true for prepareforSegue..
@IBAction func buttonPress(sender: AnyObject) { println("button pressed") if (shouldPerformSegueWithIdentifier("showme", sender: self)){ performSegueWithIdentifier("showme", sender: self)} }
This behaviour is perfectly natural, for the following reasons:
1) shouldPerformSegueWithIdentifier
is used to make sure that a segue that has been set up in Storyboards should be triggered, so it only gets called in the case of Storyboard Segues and gives you the chance to not actually perform the segue.
2) When you call performSegueWithIdentifier
yourself, shouldPerformSegueWithIdentifier
is not called because it can be assumed that you know what you are doing. There would be no point in calling performSegueWithIdentifier
but then return a NO
from shouldPerformSegueWithIdentifier
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With