사용자가 텍스트 필드를 비워 두거나 두 개의 암호를 일치시키지 않으면 오류 경고가 표시되는 응용 프로그램을 만듭니다.팝업 오류 메시지를 닫는 방법
정보가 정확하고 두 암호가 일치하면 오류 경고가 계속 표시됩니다.
코드
아래 볼 수 있습니다 ://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;
}
}
이것은 또한 표시되지 않습니다.
안녕하십니까! 제발 사람들에게 비웃지 말고 좋은 질문을하는 법을 읽으십시오 : http://stackoverflow.com/help/how-to-ask – shallowThought
showAlert는 어디에서 호출되고 있습니까? –
소리 지르고 구걸하기 위해 Downvoted. – halfer