繁体   English   中英

从 SDWebImage 中删除图像缓存

[英]Remove image cache from SDWebImage

我无法删除由 SDWebImage 缓存的图像缓存。 我正在使用“UIImageView+UIActivityIndi​​catorForSDWebImage.h ”我正在使用此代码缓存图像。

[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"image_icon.png"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

现在有时我想删除图像缓存,因为有时相同的 url 会通过服务器给我另一个图像。

我正在使用此代码删除图像缓存。

[[SDImageCache sharedImageCache] removeImageForKey:[self.imgArray objectAtIndex:indexForDelete] fromDisk:YES];

但是给了我这样的错误:

*** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSDictionaryM UTF8String]:无法识别的选择器发送到实例 0x7fcb01f9bf70”

怎么去掉缓存??

- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk中的方法- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk使用NSString作为参数。

在上面的代码中,看起来[self.imgArray objectAtIndex:indexForDelete]给了您一个NSDictionary对象,因此崩溃了。

因此,您将需要这样的内容;

NSDictionary *imageDictionary = [self.imgArray objectAtIndex:indexForDelete];
NSString *cacheKeyToDelete = [imageDictionary objectForKey:@"YourKeyForImageCacheKey"];

[[SDImageCache sharedImageCache] removeImageForKey:cacheKeyToDelete fromDisk:YES];

迅速

SDImageCache.shared.removeImage(forKey: _imageURL?.description, withCompletion: nil)

试试这个,用 SDWebImageRefreshCached 选项更新单个图像 url。

目标-C:

[self.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"???"] options:SDWebImageRefreshCached];

Swift:你可以通过方法名称来翻译它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM