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 = "请输入文字"
})