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];




UIAlertView 改版为UIAlertController_第1张图片
[专注待办](https://itunes.apple.com/cn/app/zhuan-zhu-dai-ban-ding-shi/id1103227570?mt=8)

你可能感兴趣的:(UIAlertView 改版为UIAlertController)