在我的应用程序中,我有UITableView &表格数据可以在用户请求后从远程进行更新。我使用的核心数据& NSFetchedResultsController当变化发生了,-controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
被称为:更新单元格后UITableView渲染效果不佳
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
所有工作正常,除了一两件事。有时,重新加载第一行后,它显示为无边框(边框突然消失)。什么可能是错误的?
P.S .:为了更新数据,我在后台创建新的NSManagedObjectContext
并管理NSManagedObjectContextDidSaveNotification
。当通知到达时,mergeChangesFromContextDidSaveNotification
在主线程上执行 - 因此更新也由主线程完成。
但为什么细胞第一次正确显示?代码是一样的 - 只有标签文本不同! – kpower
嗯。我在'tableView:cellForRowAtIndexPath:'代码中进行了一些更改,只在创建时设置单元格的背景,而不是每次重新加载 - 现在一切正常。 – kpower