UIAlertView已经被苹果公司废弃,现在改成了新版的UIAlertViewController,现在就来介绍一下UIAlertController怎么写。
objective-c语法:
UIAlertController
的创建和初始化:
preferredStyle有两个类型,
分别是UIAlertControllerStyleAlert 和 UIAlertControllerStyleActionSheet
![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>