2016-12-02 10 views
-1

Ich erstelle eine Anwendung, die, wenn ein Benutzer ein Textfeld leer lässt oder die beiden Kennwörter nicht übereinstimmen, eine Fehlermeldung anzeigt.So schließen Sie die Popup-Fehlermeldung

Problem ist, wenn die Informationen korrekt sind und die beiden Passwörter übereinstimmen, die Fehlermeldung wird noch angezeigt.

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

Wenn die richtigen Informationen eingegeben wurde, sollte der Benutzer in der Lage sein, eine Bestätigung zu sehen, das Konto unter Angabe erstellt wurde:

Der Code kann weiter unten sehen.

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

Dies erscheint auch nicht.

+1

Willkommen bei SO! Bitte SCHICKE NICHT AN DEN MENSCHEN und lies, wie man eine gute Frage stellt: http://stackoverflow.com/help/how-to-ask – shallowThought

+0

Wo wird showAlert aufgerufen? –

+0

Downvoted für das Schreien und Betteln. – halfer

Antwort

0

Ich schrieb die ganze Sache auf, wie Sie über dieses Problem gehen können. Sie können es von hier aus beziehen

@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

Hallo Cyril Vielen Dank für Ihre Kommentare, habe ich alle Vorschläge gemacht, die Sie gesagt haben und für aus irgendeinem Grund zeigt es immer noch die Fehlermeldung an, wenn alle Felder und Passwörter korrekt eingegeben wurden. –

+0

Hallo, ich habe auch einen zusätzlichen Fehler, Thread 1 Signal SIGABRIT –

+0

Ich hätte Ihre Frage ein wenig sorgfältiger gelesen haben. Ich antworte darauf, ich komme an einen Computer. –

Verwandte Themen