iOS8以上的版本,使用UIAlertController 替代 UIAlert 弹窗
来源:互联网 发布:win7优化精简教程 编辑:程序博客网 时间:2024/06/11 04:35
从iOS8开始,UIAlertView和UIActionSheet都不再推荐了,应该开始使用一个新的API,UIAlertController。
UIAlertController继承自UIViewController,所以显示的方法不是show,而是普通的present。另外,如果程序用了这个API,那么在iOS7上会导致crash,所以需要版本兼容
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"这个是标题吗?" message:@"这个是内容吗?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"方法测试1"); }]; UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"其他" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"方法测试2"); }]; [alert addAction:cancelAction]; [alert addAction:otherAction]; [self presentViewController:alert animated:YES completion:nil];
可以看到,最大的区别,是UIAlertController不再使用delegate的方式来触发回调,而是直接传一个block
delegate和block并没有本质区别,只是触发回调的不同方式而已,解决的都是“在未来的某个时间,调用我”的问题。delegate的复用性更好一点,创建一个delegate实例之后,可以把它设置为多个控件的delegate,减少了重复。block的优势是更加直观,阅读起来更容易,因为代码都在一处,不需要跳来跳去地读代码
但是现在既然苹果官方使用block的频率越来越高,或许这也代表了一种趋势
0 0
- iOS8以上的版本,使用UIAlertController 替代 UIAlert 弹窗
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- IOS8以上版本,使用UIAlertController代替 UIActionSheet和UIAlertView
- WKWebView的使用(iOS8.0及以上版本使用)替代UIWebView
- UIAlertController在ios8的使用
- iOS8中 UIAlertController 的新使用
- uikit 中uialert 的使用方法UIAlertController
- uialert IOS8
- ios8.0后 UIAlertController的使用
- iOS8 以上版本的定位问题
- iOS8的UIAlertController
- ios8之后的UIAlertController
- iOS uialert的使用
- 在iOS8中使用UIAlertController
- IOS8新特性之——UIAlertController的使用
- iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet)
- iOS8开发之iOS8的UIAlertController
- Caused by: java.lang.IllegalArgumentException: Illegal character in scheme at index 0:
- python实践——批量统计mongodb数据库的集合大小
- 路由器与交换机
- Linux Memory Mapping
- 安装11G数据库脚本
- iOS8以上的版本,使用UIAlertController 替代 UIAlert 弹窗
- tomcat无法启动
- MySQL 字符集
- 杭电3308 LCIS(线段树区间合并)
- Linux之共享库封装、使用的典型demo
- 黑马程序员_java基础_反射
- android studio项目如何导入到eclipse中
- hdoj 1996 汉诺塔VI 【找规律】
- Linux Kernel中的数据结构---- 其它