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];