Last active
December 22, 2020 02:51
-
-
Save marksands/76558707f583dbb8f870 to your computer and use it in GitHub Desktop.
This file contains 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
- (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. | |
} | |
} |
Have you successfully placed an image in each action button instead of text?
Did you see a way to add these buttons when swiping from left to right? like in the mail app "mark as read"?
@marksands How to set equal width for UITableViewRowAction?(Delete,More,etc)
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")!)
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)
}
What about buttons that show when the user swipes from left to right direction?
this was super useful! thanks :)
thanks !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated gist with @maddoggy1979's tips.