UIAlertView 改版為UIAlertController

UIAlertView已經被蘋果公司廢棄,現在改成了新版的UIAlertViewController,現在就來介紹一下UIAlertController怎么寫。

objective-c語法:

UIAlertController 的創建和初始化:

preferredStyle有兩個類型,
分別是UIAlertControllerStyleAlertUIAlertControllerStyleActionSheet

![icon180.png](http://upload-images.jianshu.io/upload_images/1941047-94b87873b4afffd7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction 的創建和初始化:

UIAlertAction *ok = [UIAlertAction actionWithTitle:okLabelString style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
 …… …… ……
    }];
                         
UIAlertAction *cancel = [UIAlertAction actionWithTitle:cancelLabelString style:UIAlertActionStyleCancel handler:nil];

UIAlertAction 添加到 UIAlertController

[alertController addAction:ok];
[alertController addAction:cancel];

最后彈出提示框

[self presentViewController:alertController animated:YES completion:nil];

</br>
</br>

[專注待辦](https://itunes.apple.com/cn/app/zhuan-zhu-dai-ban-ding-shi/id1103227570?mt=8)
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容