[英]Remove image cache from SDWebImage
我無法刪除由 SDWebImage 緩存的圖像緩存。 我正在使用“UIImageView+UIActivityIndicatorForSDWebImage.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.