Skip to content

Instantly share code, notes, and snippets.

@akibe
Created February 19, 2010 23:30
Show Gist options
  • Select an option

  • Save akibe/309356 to your computer and use it in GitHub Desktop.

Select an option

Save akibe/309356 to your computer and use it in GitHub Desktop.
[iPhone] DeleteRows with DeleteSections
- (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