I've got a UITableView that represents a checklist of items. Each item is in a done/undone state.
I'd like to keep all of the done items at the top of the list, so when the user clicks an item that is undone, I'd like to figure out where the row should go (at end of currently-done items list) and move it there.
I'm trying to use -moveRowAtIndexPath:toIndexPath: for my UITableView to do this.
It works well sometimes and not so well at other times.
It seems to work well when the done action kicks off another animation elsewhere on screen. For some reason, this seems to serve as a delay for the -reloadData call.
When that's not true (i.e., the only thing "happening" is the row being marked done and moving), the animation seems to get short-circuited by an automatic call to the UITableView's -reloadData method. That is, the animation begins, but about halfway through, -reloadData is called and the rows snap to their final position. It's fairly jarring from the user's perspective.
I've tracked through my code to verify that I'm not calling -reloadData myself, and it doesn't appear that I'm the one triggering this -reloadData call.
I'm OK with the automatic call to -reloadData and I understand why it's called (though you'd think it might not be necessary, but that's a different issue), but I'd really like it to wait until it completes its animation.
Here's the code I'm using:
NSIndexPath *oldPath = [NSIndexPath indexPathForRow:currentIndex inSection:0];
NSIndexPath *newPath = [NSIndexPath indexPathForRow:newIndex inSection:0];
[tableView beginUpdates];
[checklist removeObject:task];
[checklist insertObject:task atIndex:newIndex];
[tableView moveRowAtIndexPath:oldPath toIndexPath:newPath];
[tableView endUpdates];
Am I screwing something up?
-reloadDatamanually. It was just subtle and from a timer, which wasn't being reached with breakpoints enabled. Doh! Doh! Doh! ;-) - mbm29414