ios - 即使 if 语句不正确,Swift segue 也会运行

标签 ios swift if-statement segue

如果文本字段中没有文本,我试图停止 segue 运行

@IBAction func action(_ sender: Any) {
    if( email.text != ""){
        emailaddress = email.text!
        performSegue(withIdentifier: "segue", sender: self)
    }
    else
    {
        print("enter a email")
    }
}

“输入电子邮件”在输出中打印出来,但它仍然执行 segue。

最佳答案

不要将 segue 附加到按钮,因为如果 segue 直接附加到按钮,则 performSegue 将通过点击而不是通过行执行

performSegue(withIdentifier: "segue", sender: self)

只需将您的 segue 从黄色图标拖放到下一个 Controller

关于ios - 即使 if 语句不正确,Swift segue 也会运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45307566/

相关文章:

javascript - 有没有办法在 VUE html 中编写 "If Greater than"和 "If less than"语句?

ios - UIAlertController 给出错误?请在 Swift 中使用字符串数组作为按钮提供 UIAlertController 的代码

ios - 如何在 Azure 中调试测试发送?

javascript - 当 div 在 JavaScript 调用函数中调整大小时

c++ - if 语句 - 短路评估与可读性

ios - ramotion扩展集合说明不清楚

ios - 应用程序没有互联网时的 UIAlertView

ios - 如何在选择器 View 条目旁边添加图像?

ios - 将 subview 添加到 collectionview 单元格 jsqmessagesviewcontroller

iOS 应用程序因没有堆栈跟踪的未捕获异常而终止 (Swift)