views:

80

answers:

1

Hi Guys,

Can any one help me out with UITableView animating issue.

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

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

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

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

Any help on this guys.

Thanks in advance,

+2  A: 

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] inSection:0];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
Run Loop
thanks for the code, can u give me a working sample ? oI am slightly confused with how to update the data source while doing the insertion.
Ameya
earlier I would be simply adding a record to data source (NSMutableArray) and calling [self.tableView reloadData];But that would not animatedly bring in the new element .
Ameya
Please mark my answer as accepted if it helped.
Run Loop
cool thankyou very much
Ameya
just a small change in ur code @JKplz edit your answer , hope it helps some one looking for this kind of solution.[tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:[self.dataSource count] inSection:0],nil] withRowAnimation:UITableViewRowAnimationRight];
Ameya