iOS9.0以后那些被不推荐使用(deprecated)方法之:sendAsynchronousRequest was deprecated in iOS 9、UIAlertView was depr
2017-03-07 23:18
399 查看
iOS9.0以后那些被不推荐使用(deprecated)方法之:sendAsynchronousRequest was deprecated
in iOS 9、UIAlertView was deprecated
iOS9.0以后那些被不推荐使用(deprecated)方法之:sendAsynchronousRequest 和 UIAlertView 一、UIAlertview
在Xcode7 ,iOS9.0的SDK中,已经明确提示不再推荐使用UIAlertView,而只能使用UIAlertController;
点击一个按钮,然后弹出提示框的示例代码如下:
+
View Code
但是会有警告:“‘UIAlertView’ is deprecated:first deprecated in iOS 9.0 - UIAlertView is deprecated.。。。表明UIAlertView已经iOS9中被弃用(不推荐)使用。推荐使用UIAlertController。
为解决这个warning,使用UIAlertController来解决这个问题。代码如下:
通过运行发下,程序运行后的效果相同。 其中preferredStyle这个参数还有另一个选择:UIAlertControllerStyleActionSheet。选择这个枚举类型后,实现效果:提示框会从底部弹出。
-》对比:通过查看代码还可以发现,在提示框中的按钮响应不再需要delegate委托来实现了。直接使用addAction就可以在一个block中实现按钮点击,非常方便。
二、NSURLSession替换NSURLConnection
最近使用[NSURLConnection sendAsynchronousRequest]时已经警告为不推荐使用了,苹果官方推荐使用NSURLSession中的dataTaskWithRequest方法。
用NSURLConnection实现的示例代码如下:
+
View Code
推荐使用NSURLSession方法实现如下:
相关文章推荐
- iOS9.0以后那些被不推荐使用(deprecated)方法之:sendAsynchronousRequest was deprecated in iOS 9、UIAlertView was depr
- iOS9.0以后那些被不推荐使用(deprecated)方法之:sendAsynchronousRequest was deprecated in iOS 9、UIAlertView was deprecated
- UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlert
- iOS中UIAlertView的使用方法
- IOS--UIAlertView的使用方法详细
- iOS一个'initWithRequest:delegate:' is deprecated: first deprecated in iOS 9.0 - Use NSURLSession (see NSURLSession.h) Warning引发的思考
- IOS--UIAlertView的使用方法详细
- 二十三 ,iOS UIAlertView使用block来实现代理方法;
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- iOS--UIAlertView的使用方法详细
- UIAlertController的使用(ios9.0后代替UIAlertView与UIActionSheet)
- IOS 警告框 (UIAlertView)的使用方法
- UIAlertView is deprecated in iOS 8.
- Spring 和Struts2 整合 特别需要关注Session 关闭的问题:解决方法是使用 OpenSessionInViewFilter
- iPhone UIAlertView属性及使用方法
- iOS UILabel UIButton UIImageView使用方法
- iOS9使用提示框的正确实现方式(UIAlertView is deprecated)
- iOS那些你从未使用过的属性方法
- iOS开发:Xcode 7之后viewForHeaderInSection、viewForFooterInSection设置内容不产生效果的解决方法