UIAlertController和UIAlertAction

 1     @IBAction func showAlert() {
 2         
 3         let alert = UIAlertController(title: "Hello World!", message: "This is my first app", preferredStyle: .Alert)
 4         
 5         //1.默认按钮
 6         let defaults = UIAlertAction(title: "Default", style: .Default, handler: nil)
 7         alert.addAction(defaults)
 8 
 9         //2.取消按钮
10         let cancel = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
11         alert.addAction(cancel)
12         
13         //3.红色警告按钮
14         let destructive = UIAlertAction(title: "Destructive", style: .Destructive, handler: nil)
15         alert.addAction(destructive)
16         
17         presentViewController(alert, animated: true, completion: nil)
18     }

运行结果:

 

发现:UIAlertAction.Cancel 始终显示在最后一个。

 

posted on 2015-03-18 10:07  儒柚  阅读(279)  评论(0编辑  收藏  举报