Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 检查字段是否为空是';行不通_Ios_Swift_Ibaction_Hud - Fatal编程技术网

Ios 检查字段是否为空是';行不通

Ios 检查字段是否为空是';行不通,ios,swift,ibaction,hud,Ios,Swift,Ibaction,Hud,我似乎在使用这个代码时遇到了问题。正在尝试运行检查以确保字段包含文本。如果字段中没有文本,则应显示一个HUD,文本为“电子邮件/密码不能为空”。它似乎忽略了检查,直接尝试登录。当我移除强制展开时,它会停止并执行检查,但如果字段中有文本,则不会前进到HUD消息“登录” 检查是否包含文本,只需执行以下简单操作即可: if emailTxtField.text == "" || passwordTxtField.text == "" { SVProgressHUD.showError(with

我似乎在使用这个代码时遇到了问题。正在尝试运行检查以确保字段包含文本。如果字段中没有文本,则应显示一个HUD,文本为“电子邮件/密码不能为空”。它似乎忽略了检查,直接尝试登录。当我移除强制展开时,它会停止并执行检查,但如果字段中有文本,则不会前进到HUD消息“登录”


检查是否包含文本,只需执行以下简单操作即可:

if emailTxtField.text == "" || passwordTxtField.text == "" {
    SVProgressHUD.showError(withStatus: "Email/Password Can't Be Empty")
    return
}

SVProgressHUD.show(withStatus: "Signing In...")

希望这对您有所帮助。

您不需要使用guard,因为
emailTxtField.text/passwordTxtField.text
如果为空,则返回为

要获得精确的结果,请检查文本的
计数

@IBAction func logInDidTapped(_ sender: Any) {

    if let email = emailTxtField.text,
        let password = passwordTxtField.text {

        if email.count > 0 && password.count > 0 {

            SVProgressHUD.show(withStatus: "Signing In...")
        } else {

            SVProgressHUD.showError(withStatus: "Email/Password Can't Be Empty")
        }
    }
}

这些都有帮助。谢谢大家!@user5664514请随意接受正确答案,将作为未来观众的参考。
@IBAction func logInDidTapped(_ sender: Any) {

    if let email = emailTxtField.text,
        let password = passwordTxtField.text {

        if email.count > 0 && password.count > 0 {

            SVProgressHUD.show(withStatus: "Signing In...")
        } else {

            SVProgressHUD.showError(withStatus: "Email/Password Can't Be Empty")
        }
    }
}