You can do like this :
var alert:UIAlertView = UIAlertView(title: "Alert", message: "Hello", delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles:"OK")
alert.show()
Or
var alert:UIAlertView = UIAlertView(title: "Alert", message: "Hello", delegate: self, cancelButtonTitle: "Cancel")
alert.addButtonWithTitle("OK")
alert.show()
Don't forget to add the delegate
MyController : UIViewcontroller, UIAlertViewDelegate
When the user will click on the buttons, the delegate will fire this function below. So add your code here to go to DiveNumberViewController
//// MARK - UIAlertViewDelegate
func alertView(alertView: UIAlertView, clickedButtonAtIndex buttonIndex: Int) {
//index of cancel button
if buttonIndex == 0
{
//add code if needed
}
//index of OK button
if buttonIndex == 1
{
//add code to go to your controller
}
}
}
If you use a lot of UIAlertView in a same controller, you can add a tag to each UIAlertView like that. It will allow to add a specific action depending of the UIAlertView which is clicked
alertView.tag = 999
For more information, take a look on Apple's doc :
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIAlertView_Class/index.html