// // ViewController.swift // HelloWord // // Created by QHS8848 on 15/9/29. // Copyright © 2015年 QHS8848. All rights reserved. // import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //设置背景色为白色 self.view.backgroundColor = UIColor.whiteColor() } @IBAction func buttonClick1(sender: UIButton) { //alertController--Alert模式 let alertController = UIAlertController(title: "AlertController", message: "使用UIAlertController来作提示对话框的测试", preferredStyle:.Alert) //OK按钮的代码块,这里点击Ok按钮之后,再次弹出一个新的Alert let okActionHandler = {(action:UIAlertAction!)->Void in let alertMessage = UIAlertController(title: "AlertAction", message: "你点击的是Ok按钮", preferredStyle: .Alert) alertMessage.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)) self.presentViewController(alertMessage, animated: true, completion: nil) } //OKButton let okAction = UIAlertAction(title: "OK", style: .Default, handler: okActionHandler) //Cancel按钮的事件处理代码块 let cancelActionHander = {(action:UIAlertAction!) -> Void in NSLog(" Cancel Button") } //CancelButton let cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: cancelActionHander) //将UIAlertAction添加到UIAlertController上面 alertController.addAction(okAction) alertController.addAction(cancelAction) //显示 presentViewController(alertController, animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } }