Home Ask Login Register

Developers Planet

Your answer is one click away!

Junior February 2016

how to cancel segue if both UITextFields contain text

I have two UITextFields one is a normal UITextField the other is a UITextField connected to an UIPickerView. I want only one of them to respond to Mybutton and perform the correct segue To ViewControllerA if the info inserted in the fields is correct and matches my array of strings, and to ViewControllerB if the inserted text does not match my array. The UIPickerView entered text will most certainly be correct.. The only situation would be if there was text inside both of the fields how can i construct an UIAlert so when the button is pressed the action doesn't happen. or to hide my UIButton if both fields contain text


Hitendra Hckr February 2016

To make your segue conditional, you need to use shouldPerformSegueWithIdentifier:sender: as below.

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
        if identifier == "segue1Identifier"{
            //check for required conditions
            //if conditions setisfy : return true
            //else return false : this will not allow segue to perform, so prepareForSegue:sender: will not call

Post Status

Asked in February 2016
Viewed 3,376 times
Voted 13
Answered 1 times


Leave an answer

Quote of the day: live life