How to get filesystem path to image cached with SDWebImage (iOS)

前端 未结 2 984
悲哀的现实
悲哀的现实 2020-12-21 11:42

I\'m using SDWebImage for image caching at UICollectionView in my iOS app.

Everything is fine, however, when user scrolls fast over the collection view there is alwa

相关标签:
2条回答
  • 2020-12-21 12:20

    There are private SDImageCache methods to get filesystem path to cached image. We can make these methods public with a category. Just put the code below into the, say, SDImageCache+Private.h and add it to your project:

    #import "SDImageCache.h"
    
    @interface SDImageCache (PrivateMethods)
    
    - (NSString *)defaultCachePathForKey:(NSString *)key;
    - (NSString *)cachedFileNameForKey:(NSString *)key;
    
    @end
    
    0 讨论(0)
  • 2020-12-21 12:25

    I had a similar problem, see: SDWebImage showing placeholder for images in cache

    Basically I forked the project to resolve this.

    Update:

    You can just do this to avoid the flickering (this works with the master branch of the project):

    [imageView setImageWithURL:url placeholderImage:imageView.image options:0 
     progress:^(NSUInteger receivedSize, long long expectedSize) {
            imageView.image = [UIImage imageNamed:@"QuestionMarkFace.png"];
     } completed:nil];
    
    0 讨论(0)
提交回复
热议问题