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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容