如果两个 UITextFields 都包含文本,如何取消 segue

how to cancel segue if both UITextFields contain text

我有两个 UITextField,一个是普通的 UITextField,另一个是连接到 UIPickerView 的 UITextField。如果字段中插入的信息正确且与我的字符串数组匹配,我只希望它们中的一个响应 Mybutton 并执行正确的 ViewControllerA,如果插入的文本与我的数组不匹配,则执行 ViewControllerB。 UIPickerView 输入的文本肯定是正确的。唯一的情况是,如果两个字段中都有文本,我如何构建 UIAlert,以便在按下按钮时不会发生操作。或者如果两个字段都包含 text

则隐藏我的 UIButton

要使您的 segue 有条件,您需要使用 shouldPerformSegueWithIdentifier:sender:,如下所示。

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
        }
    }