SDWebImage載入圖片的URL是同一個(如何處理)

weixin_33866037發表於2018-04-09

直接code!

載入圖片時用的方法如下:

[self.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr]];

載入不出來最新的圖片,改用下面的方法,去解決問題:

[self.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:nil options:SDWebImageRefreshCached];

除了上面的修改之外,我們還需要在SDWebImage的內部,SDWebImageManager.m檔案中,大概180行左右吧,把之前的程式碼:

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

更換成如下:

if (image && options & SDWebImageRefreshCached) {
    // force progressive off if image already cached but forced refreshing
    downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
替換下面
    // remove SDWebImageDownloaderUseNSURLCache flag
    downloaderOptions &= ~SDWebImageDownloaderUseNSURLCache;
替換上面
    // ignore image read from NSURLCache if image if cached but force refreshing
    downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}

好久沒有寫更新了,以後要堅持啊!

相關文章