Ameya Ameya - 1 year ago 151
iOS Question

UITableView add cell Animation

Can any one help me out with

animating issue?

By default we have animation for deleting cell and reordering cells in

Can we have animated adding cell, if so how to do it.

I have checked out Three20, did not not get how
has done the table expand animation under MyProfile>ReTweets.

Want to try it without
Three20 frameowrk,
using the existing animation in

Answer Source

You can use the following UITableView method:

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

Example with self.dataSource being a mutable array and your table only having 1 section:

[self.dataSource addObject:@"New Item"];
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:[self.dataSource count]-1 inSection:0];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];

Note: Subtracted 1 from datasource count since NSIndexPath is zero indexed.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download