Monday 29 August 2011

Rearrangement of Rows in Table View

Hi All,
This blog describes how to move table rows upwards and downwards.


First for integrating the below code you should have a table view and the delegate methods as cellforRowAtIndexPath etc.

For Rearrangement you have to copy below methods of table view

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES; 
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {

NSString *stringToMove = [[self.dataArray objectAtIndex:sourceIndexPath.row] retain]; 
[self.dataArray removeObjectAtIndex:sourceIndexPath.row];
[self.dataArray insertObject:stringToMove atIndex:destinationIndexPath.row];
[stringToMove release];
[tableView reloadData];

} 
dataArray is my Array which contain the values displayed in table view

No comments:

Post a Comment