ios - 无法使用 SDWebImageManager 中的方法 downloadImageWithURL 缓存图像

标签 ios swift caching uiimageview sdwebimage

我正在使用下面给出的代码使用 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/

相关文章:

objective-c - 应用内购买的奇怪行为

iphone - 如何在没有 uitableview 的情况下创建基于导航的应用程序

iphone - 在 iPhone 中验证电子邮件

ios - 在 ViewModel 中格式化 UITableViewCell 日期

android - 清除 WebView 缓存的 101 种方法 - 所有这些都不起作用

ios - Flutter 将 com.apple.security.network.client 添加到 *.entitlements

ios - 使用 Model 中的 Alert 类访问 UIAlert TextField 中的文本

ios - 如何为uiview制作淡出边框

java - 进程内缓存 vs 分布式缓存与可变/不可变对象(immutable对象)的一致性

azure - 启用 Azure Redis 缓存的诊断