ios tableView reloadRowsAtIndexPaths not working

Atul Bhatia picture Atul Bhatia · May 19, 2014 · Viewed 23.2k times · Source

I have an issue where I have a UITableViewController and when the view appears I do some calculations asynchronously which should result in the updating of specific rows in the table.

Inside the viewWillAppear function I calculate the necessary rows that need to be updated as follows:

- (void)reloadPaths:(NSMutableDictionary *)bookingsDict
{
    NSMutableArray* indexArray = [NSMutableArray array];
    int i = 0;
    for (NSString *dateKey in self.eventsToShow) {
        NSMutableDictionary *venues = [bookingsDict objectForKey:dateKey];
        if (venues) {
            int j = 0;
            NSArray *events = [self.eventsToShow objectForKey:dateKey];
            for (DCTEvent *event in events) {
                NSString *venueIdString = [NSString stringWithFormat:@"%@", event.eventVenueId];
                if ([venues objectForKey:venueIdString]) {
                    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
                    [indexArray addObject:indexPath];
                }
                j++;
            }
        }
        i++;
    }
    [self.tableView reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationFade];
}

However I notice that the cellForRowAtIndexPath function is never called after and the cells do not get updated correctly. Any idea what the issue might be?

EDIT: I just noticed that if I scroll out of the view of the cell that is supposed to get updated then it gets updated when I scroll back into view. Is there no way to have it update while in view?

Answer

Hsin Chang picture Hsin Chang · May 19, 2014

How about wrap it?

[tableView beginUpdates];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];

Here are some similar problems I have found.

cellForRowAtIndexPath isn't called after reloadRowsAtIndexPaths

UITableView's reloadRowsAtIndexPaths: (NSArray *) indexPaths failing to cause a reload unless you call it twice?

Hope this helps.