iOS开发中处理图片加载会用到sd_webimage,但是假如客户端直接从oss加载图片则需要先下载图片,再进行图片渲染,这样子的话单个控件不会出现啥问题,但是假如碰到控件是渲染在cell中的话就会遇到问题,图片会无法加载,或者重复下载
为了处理这个问题,因为时间紧急,我这边直接利用对象存图片,这样子就直接解决了图片缓存问题以及加载问题,后面会完善加入队列、以及加入运存缓存操作,
核心代码
YYImageTools tools = [YYImageTools new];
tools.indexPath = indexPath;
[tools YYImageLoad:rmodel.imageTriangle isvoice:false complete:^(NSString _Nonnull file_path, NSIndexPath _Nonnull indexPathrow, UIImage _Nonnull loadImage) {
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@”imagetoolsloading*图片 %@ indexPath:%ld file_path %@”,loadImage,indexPathrow.row,file_path);
if (file_path.length > 0) {
cell.sanjiao_image.image = loadImage;
[self.mycollectionview reloadItemsAtIndexPaths:@[indexPath]];
}else{
cell.sanjiao_image.image = loadImage;
}
});
}];
来源:oschina
链接:https://my.oschina.net/u/3653720/blog/4940411