刚开始使用
cell.photoImageV.sd_setImage(with: URL(string:"http://dmimg.5054399.com/allimg/pkm/pk/22.jpg"), placeholderImage: UIImage(named:"common_placehoderImage"))
加载不出图,找不到原因,切换为下面的方法
cell.photoImageV?.sd_setImage(with: URL(string:"http://dmimg.5054399.com/allimg/pkm/pk/22.jpg"), placeholderImage: UIImage(named:"common_placehoderImage"), options: SDWebImageOptions.retryFailed) { (image:UIImage!, error:Error!, SDImageCacheTypeMemory, url:URL!) in
print("成功了吗\(String(describing: image))")
}
收到名下的错误信息,可以看出是因为请求的url是http,这是因为Xcode 7以后,苹果要求所有的网络请求都是安全的(HTTPS).所有如果本身的服务器不支持HTTPS请求的话就要修改Xcode的默认配置.
所以需要在项目中设置一下
在info.plist文件中,右击空白位置 Add Row .然后添加类型为Dictionary的NSAppTransportSecurity,在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
下图:
image.png