本文介绍了在tableview中延迟加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图以懒惰模式加载我的uitableviewcells的图像。
Im trying to load the image of my uitableviewcells in lazy mode.
我试图以最简单的方式做到这一点,我看到了很多例子但他们的目的远远超出了我的目的。
I'm trying to do it in the simplest possible way, I saw a lot of examples but they were going further than my purpose.
这就是我目前正在做的事情,它不起作用:
This is what Im doing currently, and its not working:
// Configure the cell...
Info *info = [self.Array objectAtIndex:indexPath.row];
cell.textLabel.text = info.name;
cell.detailTextLabel.text = info.platform;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//The image is downloaded in asynchronous
NSBlockOperation *downloadingImgBlock = [NSBlockOperation blockOperationWithBlock:^{
NSString* imageURL = info.imgURL;
NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:imageURL]];
cell.imageView.image = [UIImage imageWithData:imageData];
}];
[self.queue addOperation:downloadingImgBlock];
为什么它不起作用?它是如何工作的?
Why it's not working? And how could it work?
推荐答案
我终于设法用以下方式设置图像:
I finally managed to do it setting the image with:
– performSelectorOnMainThread:withObject:waitUntilDone:
下载图像后
这篇关于在tableview中延迟加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!