开发者

UITableView renders badly after updating cells

In my app I have UITableView & table data can be updated from remote after user request. I use Core Data & NSFetchedResultsController and when changes took place, -controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: is called:

- (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 NSFet开发者_C百科chedResultsChangeUpdate:
            [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;
    }
}

All works correctly, except one thing. Sometimes, after reloading the first row, it is displayed without border (border suddenly disappears). What can be wrong?

P.S.: For updating data I create new NSManagedObjectContext in background and manage NSManagedObjectContextDidSaveNotification. When notification comes, mergeChangesFromContextDidSaveNotification is performed on main thread - so updates are made from main thread also.


Most likely you've got a problem in:

tableView:cellForRowAtIndexPath:

… where you provide a cell of the wrong type or size for index zero.


This does not seem to be an issue with core data.

Try calling

 [cell.backgroundView setNeedsDisplay]; 

in order to update the cell. If it does not work, try calling setNeedsDisplay on the tableView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜