图片缓存及其显示

-(void)setModel:(CLModel*)model{

    _model= model;

    __blockUIImage*placeholderImage = [UIImageimageNamed:@"placeholder"];

    [[SDWebImageManager sharedManager] cachedImageExistsForURL:[NSURL URLWithString:_model.pictureUrl] completion:^(BOOL isInCache) {

        if(isInCache) {

            //本地存在图片,替换占位图片

            placeholderImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:model.pictureUrl];

        }

        //主线程

        dispatch_async(dispatch_get_main_queue(), ^{

            [self.IMGView sd_setImageWithURL:[NSURL URLWithString:model.pictureUrl] placeholderImage:placeholderImage];

        });

    }];

}

你可能感兴趣的:(图片缓存及其显示)