您的位置:首页 > 产品设计 > UI/UE

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方法实现如下:

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐