我从 WS 加载 UITableView 中的内容,并尝试异步加载图像。每次我“移动”表格时,图像都会再次加载。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"NewsCell";
NewsCell *cell = ......
NewsObject *obj = [self.dataSourceArray objectAtIndex:indexPath.row];
cell.labelTitle.text = obj.title;
cell.textViewNews.text = obj.summary;
cell.imgListIcon.image = nil;
dispatch_queue_t imageQ = dispatch_queue_create("imageQ", NULL);
dispatch_async(imageQ, ^{
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:obj.img]];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imgListIcon.image = [UIImage imageWithData:imageData];
[cell setNeedsLayout];
[cell.spinner stopAnimating];
});
});
dispatch_release(imageQ);
return cell;
}
有人可以帮我就这个问题提供一些建议吗?谢谢!