UIAlertController是向用戶展示彈出信息的類。用於替換UIActionSheet和UIAlertView。
初始化:
let alertController = UIAlertController(title: "My Alert", message: "This is an alert", preferredStyle:UIAlertControllerStyle.ActionSheet)
第三個參數UIAlertActionStyle有兩種類型:ActionSheet和Alert,分別對應UIAlertView和UIActionSheet
UIAlertController上可以添加Action,有三種Action:Default, Cancel 和 Destructive
alertController.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in self.presentSecondController()}))
展示
self.presentViewController(alertController, animated: true) {}
Alert
Action---Default
Action---Cancle
Action---Detructive
//只能在Alert上面添加
alertController.addTextFieldWithConfigurationHandler({ (textfield:UITextField!) in
textfield.delegate = self
textfield.placeholder = "請輸入文字"
})