2016-12-02 1 views
-1

사용자가 텍스트 필드를 비워 두거나 두 개의 암호를 일치시키지 않으면 오류 경고가 표시되는 응용 프로그램을 만듭니다.팝업 오류 메시지를 닫는 방법

정보가 정확하고 두 암호가 일치하면 오류 경고가 계속 표시됩니다.

코드

아래 볼 수 있습니다 :

//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; 
    } 
} 

이것은 또한 표시되지 않습니다.

+1

안녕하십니까! 제발 사람들에게 비웃지 말고 좋은 질문을하는 법을 읽으십시오 : http://stackoverflow.com/help/how-to-ask – shallowThought

+0

showAlert는 어디에서 호출되고 있습니까? –

+0

소리 지르고 구걸하기 위해 Downvoted. – halfer

답변

0

나는이 문제에 관해 어떻게 할 수 있는지에 대해 모든 것을 썼다. 여기에서 참조하실 수 있습니다

@IBOutlet var userNameField: UITextField! 
@IBOutlet var passwordfield: UITextField! 
@IBOutlet var confirmPasswordField: UITextField! 

@IBAction func registerButtonTapped() { 

    if userNameField.text == "" && passwordfield.text == "" && confirmPasswordField.text == "" { 
     alertController(title: "Error", message: "One or more fields are missing", cancelTitle: "Try again!") 
    } else { 

     if passwordfield.text != confirmPasswordField.text { 
      alertController(title: "Error", message: "Your passwords do not match", cancelTitle: "Try again!") 
     } else { 
      //switch views, or do whatever you want when the user correctly enters in their information 
     } 
    } 

} 

func alertController(title: String, message: String, cancelTitle: String) { 


    let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert) 
    let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel) 

    alertController.addAction(cancelAction) 
    self.present(alertController, animated: true, completion: nil) 
} 
+0

안녕하십니까, 귀하의 의견에 감사드립니다. 귀하가 언급 한 모든 제안을 작성했습니다. 모든 필드와 암호를 올바르게 입력 했는데도 여전히 오류 메시지가 표시되는 몇 가지 이유가 있습니다. –

+0

안녕하세요, 또한 스레드 1 신호 SIGABRIT –

+0

나는 당신의 질문을 조금 더 신중하게 읽었어야한다는 추가 오류가있어. 내가 컴퓨터에 연결하면 대답 할게. –

관련 문제