Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新单元格后,UITableView渲染不好_Uitableview_Core Data_Rendering - Fatal编程技术网

更新单元格后,UITableView渲染不好

更新单元格后,UITableView渲染不好,uitableview,core-data,rendering,Uitableview,Core Data,Rendering,在我的应用程序中,我有UITableView&可以在用户请求后从远程更新表数据。我使用核心数据&NSFetchedResultsController,当发生更改时,-controller:didChangeObject:atIndexPath:forChangeType:newindexath:被调用: - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIn

在我的应用程序中,我有UITableView&可以在用户请求后从远程更新表数据。我使用核心数据&NSFetchedResultsController,当发生更改时,
-controller:didChangeObject:atIndexPath:forChangeType:newindexath:
被调用:

- (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;
    }
}
除了一件事,所有的工作都正常。有时,在重新加载第一行后,它会显示为无边框(边框突然消失)。有什么不对劲


注意:为了更新数据,我在后台创建新的
NSManagedObjectContext
,并管理
nsmanagedobjectcontextdiddaveinnotification
。当收到通知时,主线程上会执行来自ContextDidSaveNotification的合并更改,因此也会从主线程进行更新。

这似乎不是核心数据的问题

试着打电话

 [cell.backgroundView setNeedsDisplay]; 

以更新单元格。如果不起作用,请尝试调用
表视图
上的
setNeedsDisplay

您很可能在以下方面遇到问题:

tableView:cellForRowAtIndexPath:

…为索引0提供了错误类型或大小的单元格

但是为什么第一次细胞显示正确呢?代码相同-只有标签文本不同!嗯。我在
tableView:cellforrowatinexpath:
code中做了一些更改,只在创建过程中设置单元格的背景,而不是每次重新加载时设置,现在一切正常。