I have a UITableView that I load via JSON. So my logic is this:
- Extract JSON (NSOperation, let's move on to the main thread)
- In the callback, parse json and insert the new data into my array of table data sources.
- Call reloadData on the TableView to show the new data.
My question is: how can I ANIMATE the arrival of new rows in a table? Right now, I'm just making them all appear right away, and what I want to do is make them live in place, because it looks cooler.
I think I want to use:
[self.theTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationRight]
But this gives me runtime complaints about the size of the update, which is different from the size in the data source.
Am I missing something about how this method should be used? Does anyone know an example when someone animates new rows in a TableView through this template?
Update: basically, I solved it thanks to Ben's leadership, with the following approach:
- Start with [self.theTableView beginUpdates];
- When I iterate over my entries in JSON, insert them at the beginning of my array, each time increasing their index through a loop.
Each time in a loop, call insertRowsAtIndexPath, for example:
NSIndexPath * indexPath; indexPath = [NSIndexPath indexPathForRow: [self.theChatEntries indexOfObject: message] inSection: 0]; [self.theTableView insertRowsAtIndexPaths: [NSArray arrayWithObject: indexPath] withRowAnimation: NO];
End with endUpdates outside the loop.
Woot.