Ios SDWebImage不从url分配图像-下载的图像有0个像素
这是我对Ios SDWebImage不从url分配图像-下载的图像有0个像素,ios,swift,uiimageview,sdwebimage,Ios,Swift,Uiimageview,Sdwebimage,这是我对UIImageView的简单扩展: extension UIImageView { func setImageWithUrl(url: String?) { setImageWithUrl(url, placeholder: nil) } private func setImageWithUrl(url: String?, placeholder: UIImage? = UIImage(), deleteCacheImage: Bool = false) { ima
UIImageView
的简单扩展:
extension UIImageView {
func setImageWithUrl(url: String?) {
setImageWithUrl(url, placeholder: nil)
}
private func setImageWithUrl(url: String?, placeholder: UIImage? = UIImage(), deleteCacheImage: Bool = false) {
image = placeholder ?? image
if let url = url {
let activityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame)))
activityIndicatorView.hidden = false
activityIndicatorView.color = UIColor.curiousBlue()
addSubview(activityIndicatorView)
bringSubviewToFront(activityIndicatorView)
activityIndicatorView.startAnimating()
let options = deleteCacheImage ? SDWebImageOptions.RefreshCached : SDWebImageOptions.LowPriority
sd_setImageWithURL(NSURL(string: url), placeholderImage: placeholder, options: options, completed: { image, error, cache, url in
activityIndicatorView.hidden = true
activityIndicatorView.stopAnimating()
activityIndicatorView.removeFromSuperview()
})
}
}
}
例如
但是块中的image
是nil
。为什么?它返回一个错误:
下载的图像有0个像素
我通过cocoapods获得了最新版本的
SDWebImage
:3.7.5找到了解决方案吗?