这就是问题所在:我在保存并将缩略图提取到Core Data后更新我的tableview,然后告诉单元更新自身 - 因此它可以在图像加载到时显示缩略图核心数据。我使用两个不同的线程作为核心数据不是线程安全的,当然所有的GUI元素都需要在主线程中发生。iOS:更新tableViewCell无限循环
但是这整个方法只是永远保持循环,并是什么原因造成的,当我重新加载线程:
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
为什么?我该如何解决这个问题?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Photo"];
Photo *photo = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = photo.title;
cell.detailTextLabel.text = photo.subtitle;
NSLog(@"Context %@", self.photographer.managedObjectContext);
[self.photographer.managedObjectContext performBlock:^{
[Photo setThumbnailForPhoto:photo];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = [UIImage imageWithData:photo.thumbnail];
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
});
}];
return cell;
}
不要,我再说一遍,不要在cellforrowatindexpath内调用重载表(cell)函数..因为它会一遍又一遍地读取图像。当你重新加载tableview或任何单元格时,它会再次调用cellforrowatindexpath(并且在你的情况下再次调用) – 2013-03-20 15:13:43
cellForRowAtIndexPath将在绘制单元格之前调用。所以它已经更新了。为什么你需要在cellForRowAtIndexPath中重新加载? – Mert 2013-03-20 15:15:28
Mert:我只是应该重新加载它,因为我直接访问了tableViewCell。 – 2013-03-20 15:22:04