我注意到在Core Data中插入带有Core Data的数据将使用tableView:cellForRowAtIndexPath:方法刷新Table View中的每个单元格。
我的应用程序首先从Web中获取100+项。当将它们添加到核心数据数据库时,将对每个单元进行tableView:cellForRowAtIndexPath:调用。我预计只有第一个8-9可见单元会刷新。我怎么才能改变呢?这是一个问题的原因是,我的应用程序在第一次调用tableView:cellForRowAtIndexPath时下载封面图像--当每个单元格调用它时,这不是一个最佳解决方案。
EDIT1: My代码完全基于来自斯坦福大学CS 192 p课程的示例。我从第14课下载了他们的Photomania.zip,并插入了tableView:willDisplayCell:forRowAtIndexPath:方法,该方法在调用该方法时在日志中显示项名。您可以在这里获取我的代码:http://uploads.demaweb.dk/Photomania.zip。正如您将看到的,表中的每个项都调用了这个方法吗?为什么?
EDIT2: --我在iOS开发程序库的NSFetchedResultsControllerDelegate中使用了这个方法。我发现withRowAnimation:UITableViewRowAnimationFade使它同时调用每个单元格的cellForRowAtIndexPath和willDisplayCell。当将其更改为withRowAnimation:UITableViewRowAnimationNone时,只调用可见的单元格。
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}发布于 2011-12-12 15:29:21
您是否重用您的单元(即提供单元重用标识符)?
您是否实现了允许视图控制器在行“联机”时插入/删除行而不是执行NSFetchedResultsControllerDelegate的[tableView reloadData]方法?在这些方法中,您应该使用'[UITableView insertRowsAtIndexPaths:withRowAnimation:]、[UITableView deleteRowsAtIndexPaths:withRowAnimations:]等‘来调整引用的行。
最后,您可以将图像加载逻辑移到UITableView委托方法tableView:willDisplayCell:forRowAtIndexPath:中。这样,只有在实际要显示的时候才会调用它。
https://stackoverflow.com/questions/8475815
复制相似问题