Sponsors

 

Tuesday, August 11, 2009

Clarification on beginUpdates and endUpdates methods

As I was doing some studying regarding different aspects of working with a UITableView, I came across some information about beginUpdates and endUpdates, which, I hope to share with you to clarify how these guys actually work!

The SDK gives you several methods (of your table view) you can call to animate the addition and deletion of rows/sections on your table:

Animating the adding of a row:
-(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation *)animation;

Deleting of a row:
-(void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation *)animation;

Adding a section:
-(void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation *)animation;

Deleting a section:
-(void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation *)animation;

Calling a combination of these to say add a row in one spot and delete another row in another spot will generate two different animations in the order that you specified them.

To make things look better, there is beginUpdates and endUpdates. The beginUpdates and endUpdates is basically like a two-phased commit you do on a database... only for animation! If you wrap your sequence of adds/deletes with these guys it will animate the deletions and inserts all as one orchestrated animation! Giving you that professional polished look!

I found some interesting table view code you may want to look at out on the web that uses allot of this. NOTE: I haven't actually tested this code yet so I don't know how well it will actually work.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.