Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to perform reloadSections after [self.tableView endUpdates] is done animating

I need to perform

[[self tableView] reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];

after

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller has sent all current change notifications, so tell the table view to process all updates.
    [self.tableView endUpdates];    
}

is done animating.

I want do that this way because I need to re-configure some cells in the section when a cell is deleted from the section. This is because the first and the last cell of the section have different backgrounds than the cells between them. A single cell has a different background all together. If I don't re-configure the cells left in the section, it could result in an akward view.

Calling reloadSections during controllerDidChangeContent is too soon and crashes because a cell can no longer be found.

like image 423
Tycho Pandelaar Avatar asked Mar 14 '11 17:03

Tycho Pandelaar


2 Answers

If you want to pass more than 1 argument to a method with delay, wrap the method call in your own method:

- (void)reloadSections {
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1]
        withRowAnimation:UITableViewRowAnimationNone];
}

Then when you want to reload:

[self performSelector:@selector(reloadSections) withObject:nil afterDelay:.2];
like image 138
GendoIkari Avatar answered Nov 02 '22 22:11

GendoIkari


What about this?

[CATransaction begin];

[CATransaction setCompletionBlock:^{
    // animation has finished
}];

[tableView beginUpdates];
// do some work
[tableView endUpdates];

[CATransaction commit];
like image 31
Rudolf Adamkovič Avatar answered Nov 02 '22 23:11

Rudolf Adamkovič