Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode storyboard cancel push if a condition is not met

I have a storyboard with a button in a Navigation View Control, this control has textfields in as well, which uses the storyboard segue push. However, I have some input checking, and I alert the user if any of the text fields are empty.

I can do this, BUT it alerts the user, and then switches to the other view.

Is there a way to cancel this push if an if condition is not met in the button Pressed method?

N.B This push was created by the storyboard interface, not by code.

like image 597
H Bellamy Avatar asked Jan 28 '12 09:01

H Bellamy


1 Answers

Don't create the segue by dragging from the button to the destination controller. Instead, just drag from the source controller to the destination controller to create a segue. Click on the segue and use the attribute inspector to specify the segue is a push and give the segue an identifier (goToDestination). Then connect the button to an IBAction in the source view controller. In the IBAction method do your checking and if you want to do the push add this line of code:

[self performSegueWithIdentifier: @"goToDestination" sender: self];
like image 76
T.J. Avatar answered Sep 20 '22 03:09

T.J.