Reputation: 21
I have an UIAlertView in Swift in XCode and would like to have two buttons, one that dismisses the alert and the other that I can tag so that it opens up a different ViewController. Right now both buttons are tagged and I just want to tag the one.
var alertview:UIAlertView = UIAlertView()
alertview.title = "Error!"
alertview.message = "You will need to do this before proceeding."
alertview.delegate = self
alertview.addButtonWithTitle("OK")
alertview.addButtonWithTitle("Not now")
alertview.tag = 888
alertview.show()
}
Upvotes: 1
Views: 886
Reputation: 119242
UIAlertController
is a replacement for UIAlertView which gives you a modern block-based syntax for adding actions to the alert. Use that instead. The cancel action simply has no handler.
If you must still use UIAlertView then you perform actions based on the index of the buttons pressed, and the cancel button has a specific location (that's why you have the special initialiser with the cancel button title and the other button titles). You then handle the button presses in the delegate method.
Upvotes: 1