0

I would like to be able to add an alert view to my login screen that says Incorrect Username/ Password when the info submitted is incorrect. I am using Swift 2. I'm still new to learning code and I am unsure how to add this action.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
John Harris
  • 109
  • 1
  • 1
  • 9
  • 3
    See the answer in the following thread (`UIAlertControllerStyleAlert`) http://stackoverflow.com/questions/24022479/how-would-i-create-a-uialertview-in-swift – dfrib Dec 20 '15 at 20:09
  • Take a look at this, i've written a small repo to do this for you. https://github.com/Swinny1989/iOS-Swift-Popups – Swinny89 Dec 21 '15 at 11:19

1 Answers1

0

Just use this code to display the alert:

func wrongLogin(input: String) {

    var alert = UIAlertController(title: "Incorrect", message: "The \(input) is wrong. Try again.", preferredStyle: UIAlertControllerStyle.Alert)
    //add a cancel button
        alert.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Cancel, handler: nil))
    // Show it

        showViewController(alert, sender: self)
    }

Then when calling it just pass in if it's the username or the password.

You can do that like this wrongLogin("password") or wrongLogin("username")

For further info see this answer.

Hope that helps, Julian.

Community
  • 1
  • 1
Julian E.
  • 4,687
  • 6
  • 32
  • 49