Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS 8 beta 2: ''tableView:editActionsForRowAtIndexPath:"
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *moreAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"More" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// show UIActionSheet
}];
moreAction.backgroundColor = [UIColor greenColor];
UITableViewRowAction *flagAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Flag" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// flag the row
}];
flagAction.backgroundColor = [UIColor yellowColor];
return @[moreAction, flagAction];
}
/*
* EDIT on 06.07.2014 because of some confusion if 'tableView:commitEditingStyle:forRowAtIndexPath:' is needed.
* It IS needed.
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// No statement or algorithm is needed in here. Just the implementation
}
@Dimillian

This comment has been minimized.

Copy link

@Dimillian Dimillian commented Jun 24, 2014

Does it work? I implemented it, can't swipe my UITableView cells.

@siancu

This comment has been minimized.

Copy link

@siancu siancu commented Jun 30, 2014

Yeah, same for me, I couldn't get it to work. I even tried to set the table into edit mode beforehand, but it still didn't work.

@scheinem, if you manage to make it work, can you post a more detailed example?

@r-peck

This comment has been minimized.

Copy link

@r-peck r-peck commented Jun 30, 2014

You still have to implement tableView:commitEditingStyle:forRowAtIndexPath: to get the buttons to appear. Still seems unpolished though.

@r-peck

This comment has been minimized.

Copy link

@r-peck r-peck commented Jun 30, 2014

Note that method is not called when the buttons are tapped (and header docs indicate this should be the case).

@siancu

This comment has been minimized.

Copy link

@siancu siancu commented Jul 2, 2014

Let's wait for the next drop then, hopefully it'll work better :-)

@scheinem

This comment has been minimized.

Copy link
Owner Author

@scheinem scheinem commented Jul 6, 2014

@r-peck @siancu Did you implement tableView:commitEditingStyle:forRowAtIndexPath:?

Just insert the following code into your TableViewController.m and it should work:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Nothing is needed here
}
@rubencodes

This comment has been minimized.

Copy link

@rubencodes rubencodes commented Jul 13, 2014

Thanks! This has been super helpful! One question, though: when selecting one of the options presented, the row doesn't return to its original position. Any thoughts on how to get it back it its resting position?

EDIT: Solved by adding [self.tableView setEditing:NO] to the action handler per suggestion by @marksands https://twitter.com/marksands/status/488430429612277761

@dleute

This comment has been minimized.

Copy link

@dleute dleute commented Jul 19, 2014

This doesn't work for insert indicator rows for me. Only delete indicators. I'm hoping this works in iOS 8 final. I need the control space in my app.

@jellyZ

This comment has been minimized.

Copy link

@jellyZ jellyZ commented Sep 1, 2014

good~

@MVakas

This comment has been minimized.

Copy link

@MVakas MVakas commented Sep 17, 2014

Worked for me like a charm.

@omgbbqhaxx

This comment has been minimized.

Copy link

@omgbbqhaxx omgbbqhaxx commented Oct 12, 2014

İs this code work with ios 7 or 6 ? or only work with ios8 + ?

@scheinem

This comment has been minimized.

Copy link
Owner Author

@scheinem scheinem commented Oct 30, 2014

@omgbbqhaxx Only 8.0 beta 2 and above

@guomingman

This comment has been minimized.

Copy link

@guomingman guomingman commented Nov 7, 2014

but why we should add

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    // Nothing is needed here
    }
    I debug it ,and didn't execute this API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment