我正在创建一个应用程序,当用户将文本字段留空或不会使两个密码匹配时,将显示错误警报。如何关闭弹出错误消息
问题是当信息正确并且两个密码匹配时,错误警报仍在呈现。
的代码可以看到下面:
//creating an action that will check when the sign up button is selected.
@IBAction func registerButtonTapped(_ sender: Any) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
let userRepeatPassword = repeatPasswordTextField.text;
// if one of the fields is empty the user must repeat the password
if ((userEmail?.isEmpty)! || (userPassword?.isEmpty)! || (userRepeatPassword != nil)) {
//this is the alert pop up shown to the user.
let alertController = UIAlertController(
title: "Error!!!!!!",
message: "Something Went Wrong, Try Again",
preferredStyle: UIAlertControllerStyle.alert
)
let cancelAction = UIAlertAction(
title: "Cancel",
style: UIAlertActionStyle.destructive) { (action) in
}
let confirmAction = UIAlertAction(
title: "OK", style: UIAlertActionStyle.default) { (action) in
}
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true){() -> Void in
return;
}
}
func registerButtonTapped(_ sender: Any) {
//check if password and repeat password are the same
if (userPassword != userRepeatPassword) {
//display an alert message, user will not be able to continue // not too sure if this works
let alertController = UIAlertController(
title: "Error!!!!!!",
message: "Something Went Wrong Try Again",
preferredStyle: UIAlertControllerStyle.alert
)
let cancelAction = UIAlertAction(
title: "Cancel",
style: UIAlertActionStyle.destructive) { (action) in
}
let confirmAction = UIAlertAction(
title: "OK",
style: UIAlertActionStyle.default) { (action) in
}
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true){() -> Void in
return;
}
当正确的信息已经输入的用户应该能够看到一个确认,说明已创建的帐户。
//display prompt message (confirmation)
//this will show a message to the user showing that the registration has been successful this is not working
func showAlert() {
let alertController = UIAlertController(title: "Thank You", message: "Registration Has Been Completed. Thank You", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(defaultAction)
self.present(alertController, animated: true){() -> Void in
return;
}
}
这也没有显示出来。
欢迎来到SO!请不要在人们面前喋喋不休,并阅读如何提出一个好问题:http://stackoverflow.com/help/how-to-ask – shallowThought
showAlert在哪里被调用? –
呐喊助威,呐喊助威。 – halfer