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;
}
誰かがこの問題についてアドバイスをくれますか? ありがとうございました!