我正在尝试在用户输入的密码与输入的密码确认不匹配时显示警报。但是,当它们不匹配时,依旧会发生。谢谢
@IBAction func signUpAction(_ sender: Any) {
if password.text != passwordConfirm.text {
let alertController = UIAlertController(title: "Password Incorrect", message: "Please re-type password", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
else{
Auth.auth().createUser(withEmail: email.text!, password: password.text!){ (user, error) in
if error == nil {
self.performSegue(withIdentifier: "signupToHome", sender: self)
}
else{
let alertController = UIAlertController(title: "Error", message: error?.localizedDescription, preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .cancel, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true, completion: nil)
}
}
}
答案 0 :(得分:1)
您似乎将segue钩到了按钮上,将其删除并使其成为vc本身的源代码(将其从IB中vc的黄色圆形图标顶部拖出),因为将segue附加到按钮上可以执行任何操作动作的内部逻辑