Prevent segue in prepareForSegue method?

It’s possible in iOS 6 and later:
You have to implement the method

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 

In your view controller. You do your validation there, and if it’s OK then return YES; if it’s not then return NO; and the prepareForSegue is not called.

Note that this method doesn’t get called automatically when triggering segues programmatically. If you need to perform the check, then you have to call shouldPerformSegueWithIdentifier to determine whether to perform segue.

Leave a Comment