Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cellForRowAtIndexPath isn't called after reloadRowsAtIndexPaths

As the Apple Doc said,

Reloading a row causes the table view to ask its data source for a new cell for that row.

I combine UITableView with NSFetchedResultsController:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    if (self.tableView.isEditing) 
    {
        [self.tableView setEditing:NO animated:YES];
    }
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.tableView endUpdates];

    [self updateTabItemBadge];
    [self.noDataView setHidden:![self isNoData]];

    WXINFO(@"controllerDidChangeContent");
}

Between the above two functions, I reload the target cell:

enter image description here

    case NSFetchedResultsChangeUpdate: {
        if (indexPath) {
            [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }

enter image description here

I set a breakpoint at Line1563, to check that the reloadRowsAtIndexPaths has been called, but after that, - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath wasn't called.

So, my cell could not be updated.

Somebody can tell me why? Thanks.

like image 862
Jason Lee Avatar asked Jul 03 '13 03:07

Jason Lee


1 Answers

Wrap it in:

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
like image 71
anuragbh Avatar answered Oct 14 '22 04:10

anuragbh