简体   繁体   English

从 SDWebImage 中删除图像缓存

[英]Remove image cache from SDWebImage

I am not able to remove image cache which are cached by SDWebImage.我无法删除由 SDWebImage 缓存的图像缓存。 I am using "UIImageView+UIActivityIndicatorForSDWebImage.h " I am caching image with this code.我正在使用“UIImageView+UIActivityIndi​​catorForSDWebImage.h ”我正在使用此代码缓存图像。

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

Now sometime i want to remove cache of image because sometime same url will give me another image by server.现在有时我想删除图像缓存,因为有时相同的 url 会通过服务器给我另一个图像。

I am removing image cache using this code.我正在使用此代码删除图像缓存。

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

But is give's me error like:但是给了我这样的错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM UTF8String]: unrecognized selector sent to instance 0x7fcb01f9bf70' *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[__NSDictionaryM UTF8String]:无法识别的选择器发送到实例 0x7fcb01f9bf70”

How to remove cache ??怎么去掉缓存??

The method - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk in the SDWebImage takes NSString as an argument. - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk中的方法- (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk使用NSString作为参数。

In your above code it looks like [self.imgArray objectAtIndex:indexForDelete] gives you an an NSDictionary object and hence the crash. 在上面的代码中,看起来[self.imgArray objectAtIndex:indexForDelete]给了您一个NSDictionary对象,因此崩溃了。

So you would need something like this; 因此,您将需要这样的内容;

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)

Try this, updating single image url with SDWebImageRefreshCached options.试试这个,用 SDWebImageRefreshCached 选项更新单个图像 url。

Objective-C:目标-C:

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

Swift: u can translate it by method name Swift:你可以通过方法名称来翻译它

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

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