To show an alert view in swift while using iOS8.
Here is an example of how to use it:
var MyAlert = UIAlertController(title: "Logout", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.Alert)
var MyOkayAction = UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default) {
// Handle Okay logic here when user press Okay button, like
action in self.performSegueWithIdentifer("storyboard_segue_identifier", sender:self)
}
var MyCancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default) {
// Handle Cancel Logic here - when user press cancel button, like
action in self.dismissViewControllerAnimated(true, completion: nil)
}
MyAlert.addAction(MyOkayAction)
MyAlert.addAction(MyCancelAction)
self.presentViewController(MyAlert, animated: true, completion: nil)
Please note that if you are using iOS8, you should be using UIAlertController instead for UIAlertView is deprecated:
0 Comment(s)