これが問題です: サムネイルを Core Data に保存してフェッチした後、テーブルビューを更新してから、セル自体を更新するように指示します。これにより、画像が Core Data にロードされたときにサムネイルを表示できます。Core Dataはスレッドセーフではなく、もちろんすべてのGUI要素がメインスレッドで発生する必要があるため、2つの異なるスレッドを使用します。
しかし、このメソッド全体が永遠にループし続けるだけで、原因はスレッドをリロードしたときです。
[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;
}