问题描述
好的伙计们,这就是我的情况。
Ok Guys, here's the situation I have.
我正在使用带有核心数据的UITableViewController。该表有大约200个单元格,基本上用作清单。当你点击一个单元格时,那个单元格有一个被切换的复选框设置为UITableViewCell.imageView(分配给标签左边的UIImageView)。
I'm using a UITableViewController with Core Data. The table has about 200 cells, that basically function as a checklist. When you tap a cell, that cell has a checkbox that gets toggled set to the UITableViewCell.imageView ( the UIImageView assigned to the left of the label).
我随时使用下面两种方式中的任何一种来更新表,更新大约需要1到2秒......而且据我所知,它似乎正在重新加载每个单元格。如何强制只更新刚刚被点击的单元格?
Anytime I use either of the two ways below to update the table, it takes about 1 - 2 seconds for the update ... and from what I can tell, it seems to be reloading every cell. How can I force only the cell that was just tapped to be updated?
[self.tableView reloadData];
或
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[self.tableView beginUpdates];
}
- (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:NO];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex]
withRowAnimation:NO];
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:NO];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:NO];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath]
atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:NO];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:NO];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self.tableView endUpdates];
}
推荐答案
你需要这个:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
这篇关于在UITableview上仅重新加载一个UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!