未调用警报功能,但没有错误
@objc func handleSignUp(){
guard let email = emailTextField.text else {
let alertemail = UIAlertController(title: "Error!", message: "Please enter a valid email address!", preferredStyle: UIAlertController.Style.alert)
let actionemail = UIAlertAction(title: "OK", style: .default) { (actionemail) in
alertemail.dismiss(animated: true, completion: nil)
}
alertemail.addAction(actionemail)
self.present(alertemail, animated: true, completion: nil)
return
}
guard let password = passwordTextField.text else {
let alertpassword = UIAlertController(title: "Error!", message: "Please enter a valid password!", preferredStyle: UIAlertController.Style.alert)
let actionpassword = UIAlertAction(title: "OK", style: .default) { (actionpassword) in
alertpassword.dismiss(animated: true, completion: nil)
}
alertpassword.addAction(actionpassword)
return
}
createUser(withEmail: email, password: password)
}
答案 0 :(得分:0)
text
对象的UITextField
属性(与UILabel
不同)从不nil
。 This string is @"" by default。
您可以添加一个检查字符串是否为空
guard let email = emailTextField.text, !email.isEmpty else { ...
但是您应该验证电子邮件地址