我爱编程IOS

图片缓存及其显示

2018-03-19  本文已影响0人  开心就好2008

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

        });

    }];

}

上一篇 下一篇

猜你喜欢

热点阅读