简体   繁体   中英

Remove image cache from SDWebImage

I am not able to remove image cache which are cached by SDWebImage. I am using "UIImageView+UIActivityIndicatorForSDWebImage.h " I am caching image with this code.

[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.

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'

How to remove cache ??

The method - (void)removeImageForKey:(NSString *)key fromDisk:(BOOL)fromDisk in the SDWebImage takes NSString as an argument.

In your above code it looks like [self.imgArray objectAtIndex:indexForDelete] gives you an an NSDictionary object and hence the crash.

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.

Objective-C:

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

Swift: u can translate it by method name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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