UIAlertController的使用(Swift)

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上還能添加Textfield,用戶能夠編輯

//只能在Alert上面添加
        alertController.addTextFieldWithConfigurationHandler({ (textfield:UITextField!) in
            textfield.delegate = self
            textfield.placeholder = "請輸入文字"
        })




發佈了68 篇原創文章 · 獲贊 9 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章