我正在使用下面给出的代码使用 downloadImageWithURL
方法下载图像并将图像分配给 UIImageView
并使用 SDImageCache( ).storeImage
,但我无法缓存图像。我错过了什么吗?
这是我的代码:
SDWebImageManager.sharedManager().downloadImageWithURL(profileImageURL,
options: SDWebImageOptions.HighPriority,
progress: { (min:Int, max:Int) -> Void in
})
{ (image:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool, url:NSURL!) -> Void in
if (image != nil)
{
self.userProfilePic.image = image
SDImageCache.sharedImageCache().storeImage(image, forKey: "userProfilePicImage", toDisk: true)
}
}
最佳答案
查看github页面,有专门针对UIImageView的分类。在 https://github.com/rs/SDWebImage 上寻找 Using UIImageView+WebCache category with UITableView
正如他们举的例子。
这既设置图像,缓存它,又在获取图像时使用占位符图像。
关于ios - 无法使用 SDWebImageManager 中的方法 downloadImageWithURL 缓存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39287355/