Using iOS 5 storyboards, on a button I am performing a segue, what I want is to do validation on my textfield and if validation is failed I have to stop segue and throw an alert. Whats the way to do it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your deployment target is iOS 6.0 or later
You can simply implement the
shouldPerformSegueWithIdentifier:sender:method on your source view controller. Make this method returnYESif you want to perform the segue, orNOif you don’t.If your deployment target is earlier than iOS 6.0
You will need to change the way your segue is connected in the storyboard and write a little more code.
First, set up the segue from the button’s view controller to the destination view controller, instead of directly from the button to the destination. Give the segue an identifier like
ValidationSucceeded.Then, connect the button to an action on its view controller. In the action, perform the validation and either perform the segue or show an alert based on whether the validation succeeded. It will look something like this: