我尝试从UITableViewCell中异步加载服务器的UIImages。 我的代码在模拟器中工作正常,但不在设备上。我的代码如下,UIImage无法正常工作?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
IScopeCustomTableCell *cell = (IScopeCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellClassName];
if (!cell){
NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil];
cell = [topLevelItems objectAtIndex:0];
}
cell.delegate = self;
cell.videoTitle.text = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoTitle"];
cell.videoLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoLink"];
cell.videoThumbnailImageLink = [[videoDataArray objectAtIndex:indexPath.row] objectForKey:@"VideoThumbnail"];
cell.videoThumbnail.tag = indexPath.row;
cell.tag = indexPath.row;
[cell.activityIndicator startAnimating];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage:)
object:cell];
[queue addOperation:operation];
return cell;
}
- (void)loadImage:(IScopeCustomTableCell *)cell {
NSLog(@"Image link :- %@", cell.videoThumbnailImageLink);
//NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]];
NSData* imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.videoThumbnailImageLink]];
UIImage* image = [UIImage imageWithData:imageData];
cell.videoThumbnail.image = image;
[cell.activityIndicator stopAnimating];
[cell.activityIndicator removeFromSuperview];
//[self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO];
}
上模拟器上述代码细但不能在设备,becoz,的UIImage *图像获取即使含有适当的数据的NSData的LoadImage方法(0X0)空。
文件大小的howmany MB来自服务器??? – parag 2012-03-26 07:00:33
@paragkavar,20KB – Tirth 2012-03-26 07:22:50
对不起,明显的,但你已经检查你的设备可以访问网络,不是吗?另外,每次单元显示时发射一个线程并不是最好的解决方案。您可以在Web上找到许多异步加载图像的教程。 – Leonardo 2012-03-26 07:31:47