-(void)setModel:(SheBeiModel *)model{
// 先从缓存中查找图片
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey: [NSString stringWithFormat:@"%@%@",request_Img_url,model.image]];
// 没有找到已下载的图片就使用默认的占位图,当然高度也是默认的高度了,除了高度不固定的文字部分。
if (!image) {
image = [UIImage imageNamed:@"erwrw"];
// 图片不存在,下载图片
[self downloadImage:[NSString stringWithFormat:@"%@%@",request_Img_url,model.image]];
}
else
{
self.imaShow.image = image;
//手动计算cell
CGFloat imgHeight = image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width;
[self.imaShow mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top);
make.left.equalTo(self.contentView.mas_left).offset(10);
make.right.equalTo(self.contentView.mas_right).offset(-10);
make.height.mas_equalTo(imgHeight);
make.bottom.equalTo(self.contentView.mas_bottom).offset(-20);
}];
}
_currentLab.text = [NSString stringWithFormat:@"图片-%ld",self.currentTag];
//
}
- (void)downloadImage:(NSString*)imageURL
{
// 利用 SDWebImage 框架提供的功能下载图片
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageURL] options:(SDWebImageDownloaderUseNSURLCache) progress:^(NSInteger receivedSize, NSInteger expectedSize) {
} completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
[[SDImageCache sharedImageCache] storeImage:image forKey:imageURL toDisk:YES];
dispatch_async(dispatch_get_main_queue(), ^{
// 回到主线程做操做
// 请求完成 刷新代码
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloaddata" object:nil];
});
}];
}