// // 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() } }