Created
February 19, 2010 23:30
-
-
Save akibe/309356 to your computer and use it in GitHub Desktop.
[iPhone] DeleteRows with DeleteSections
This file contains hidden or 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
| - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { | |
| if (editingStyle == UITableViewCellEditingStyleDelete) { | |
| // Delete the row from the data source | |
| NSMutableArray* sect = (NSMutableArray*)[tableContents objectAtIndex:indexPath.section]; | |
| [sect removeObjectAtIndex:indexPath.row]; | |
| if ([sect count] == 0) | |
| [tableContents removeObjectAtIndex:indexPath.section]; | |
| [tableView beginUpdates] | |
| [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; | |
| //if the section is empty remove it | |
| if ([sect count] == 0){ | |
| [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; | |
| } | |
| [tableView endUpdates] | |
| [tableView reloadData]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment