IBOutlet var statusLabelAlert : UILabel @IBAction func alertButton(sender : AnyObject) { let alert = UIAlertController(title: "Alert", message: "This is an Alert", preferredStyle: UIAlertControllerStyle.Alert) alert.addAction(UIAlertAction(title: "1st", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in statusLabelAlert.text = "1st" })) alert.addAction(UIAlertAction(title: "2nd", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in statusLabelAlert.text = "2nd" })) self.presentViewController(alert, animated: true, completion: nil) }
If you do not want to do sth when the button is clicked:
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
source share