Created
February 15, 2013 08:43
-
-
Save derektu/4959182 to your computer and use it in GitHub Desktop.
Code snippet to manage TableView rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------- | |
// To add a row | |
//-------------------------------------------------------------- | |
// TODO: append one row to self.dataArray | |
// | |
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:self.dataArray.numberOfItems - 1 inSection:0]; | |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] | |
withRowAnimation:UITableViewRowAnimationAutomatic]; | |
// Make sure the added row is visible | |
// | |
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; | |
//-------------------------------------------------------------- | |
// To delete a row at 'index' | |
//-------------------------------------------------------------- | |
// TODO: remove the specified row from self.dataArray | |
// | |
// Update table view | |
// | |
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:index inSection:0]; | |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] | |
withRowAnimation:UITableViewRowAnimationAutomatic]; | |
//-------------------------------------------------------------- | |
// To update a row at 'index' | |
//-------------------------------------------------------------- | |
// TODO: update the row in self.dataArray | |
// | |
// Update table view | |
// | |
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:index inSection:0]; | |
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] | |
withRowAnimation:UITableViewRowAnimationAutomatic]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment