bparanj bparanj - 4 months ago 22
Objective-C Question

UITableView Animation Headache

NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0];
NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0];
NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil];
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

The above code works and it animates. The problem is that I have lot of data and I don't want to hard-code the row indexes. Since I have only one section in my table section can be 0. How can I dynamically generate NSArray of NSIndexPath objects?

Or is there an easier way to animate the table view. All the rows in my table view change when the user clicks the tab on top of the table view.


To generate the array of index paths, you could just loop:

	NSMutableArray *updatedPaths = [NSMutableArray array];
	for (NSNumber *row in someArray) {
		NSIndexPath *updatedPath = [NSIndexPath indexPathForRow:[row intValue] inSection:0];
		[updatedPaths addObject:updatedPath];
	[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

If you reload all data in your TableView, why not just call the reloadData method?