Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
- (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
[self.tableView setEditing:NO];
moreAction.backgroundColor = [UIColor lightGrayColor];
UITableViewRowAction *blurAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Blur" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.tableView setEditing:NO];
blurAction.backgroundEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
[self.objects removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
return @[deleteAction, moreAction, blurAction];
// 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.
Copy link

maddoggy1979 commented Jul 4, 2014

Thanks for the snippet...
May be worth noting that the order in which you return the actions determines their position. The first action returned is the right-most action button.
So that its more iOS-like with the delete button at the far right, change the order they are returned as below:
return @[deleteAction, moreAction];

Another point for those that are interested:
UITableViewRowActionStyleDefault => Red(?) button
UITableViewRowActionStyleNormal => Grey Button
UITableViewRowActionStyleDestructive => Red Button

To change the color:
[moreAction setBackgroundColor:[UIColor orangeColor]];

Add blur and vibrancy effects (not sure what's going on here... these seem more targeted to imageViews)

Create a blur effect:
UIBlurEffect *myBlur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

Add a vibrancy effect to the blur effect if you want:
[moreAction setBackgroundEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];

Apply to the action:
[moreAction setBackgroundEffect:[UIVibrancyEffect effectForBlurEffect:myBlur]];
[moreAction setBackgroundEffect:myBlur];

Copy link

rubencodes commented Jul 13, 2014

How can I return the row to its initial position after its action has been triggered?

EDIT: Solved by adding [self.tableView setEditing:NO] to the action handler per suggestion by @marksands

Copy link

marksands commented Jul 13, 2014

Updated gist with @maddoggy1979's tips.

Copy link

normalnorman commented Aug 28, 2014

Have you successfully placed an image in each action button instead of text?

Copy link

kalsky commented Oct 6, 2014

Did you see a way to add these buttons when swiping from left to right? like in the mail app "mark as read"?

Copy link

akjesto commented Oct 14, 2014

@marksands How to set equal width for UITableViewRowAction?(Delete,More,etc)

Copy link

theHellyar commented Nov 5, 2014

how do you swap the title text for an image/icon?

this looks like a work around but not ideal (swift):
deleteAction.backgroundColor = UIColor(patternImage: UIImage(named:"sample")!)

Copy link

bnickel commented Nov 12, 2014

You can have your delete action call the delegate method to simplify things:

let deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (rowAction, indexPath) -> Void in
    self.tableView(tableView, commitEditingStyle: .Delete, forRowAtIndexPath: indexPath)

Copy link

gh0st commented Nov 16, 2014

What about buttons that show when the user swipes from left to right direction?

Copy link

joyceyan commented Jan 24, 2015

this was super useful! thanks :)

Copy link

zhysan commented Oct 4, 2015

thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment