"OK" button in warning message -

Asked

Viewed 348 times

0

Can someone help me

What is the correct way in Swift 2? asks to remove "Let okAction", but then I lose the reference and the alert is no button.

Let okAction = Uialertaction(title: "OK", style: Uialertactionstyle.Default, Handler: nil)

Full code to facilitate:

    @IBAction func singUpButtonTapped(sender: AnyObject) {

    let userEmail = userEmailAddressTextField.text
    let userPassword = userPasswordTextField.text
    let userPasswordRepeat = userPasswordRepeatTextField.text
    let userFirstName = userFirstNameTextField.text
    let userLastName = userLastNameTextField.text


    if( userPassword != userPasswordRepeat) {

        displayAlertMessage("Passwords do not match")
        return
    }

    if(userEmail!.isEmpty || userPassword!.isEmpty || userFirstName!.isEmpty || userLastName!.isEmpty )
    {
        displayAlertMessage("Passwords do not match")
        return
    }


}

func displayAlertMessage(userMessage:String)
{
    let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)

    self.presentViewController(myAlert, animated: true, completion: nil)

}

1 answer

3

Your UIAlertAction is okay. As it did not actually post the error presented, I believe it is Warning compilation warning that you are not using the created action, once not used, can be removed.

What you need to do is add your action at the alert:

func displayAlertMessage(userMessage:String)
{
    let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)

    myAlert.addAction(okAction)

    self.presentViewController(myAlert, animated: true, completion: nil)

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.