Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @marksands marksands revised this gist Jul 2, 2014. 1 changed file with 10 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions DemonstratesUITableViewRowActionUITableViewController.m
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,13 @@ - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NS

    return @[moreAction, deleteAction];
    }

    // From Master/Detail Xcode template
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
    [self.objects removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }
    }
  2. @marksands marksands created this gist Jul 2, 2014.
    11 changes: 11 additions & 0 deletions DemonstratesUITableViewRowActionUITableViewController.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"More" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
    // maybe show an action sheet with more options
    }];

    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
    [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }];

    return @[moreAction, deleteAction];
    }