Preface
I believe every iOS developer knows that the left swipe deletion function of UITableView is very cool. Sometimes the left swipe requires more than one function to delete, sometimes there will be other functions such as top-mounting. At this time, we need to customize the left swipe by ourselves.
Sample code
-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel Favorites" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { NSLog(@"Favorite Click Event"); }]; UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Top" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) { NSLog(@"Up to button click event"); }]; =RGB(215, 59, 16); NSArray *arr = @[rowAction,rowAction2]; return arr; }
Summarize
We can use UITableViewRowAction to create objects. The code blocks behind are the method of executing after clicking. Add the created objects to the array. In this way, we can customize them at will, and we can also choose the colors ourselves, which is very convenient. The above is the entire content of this article. I hope it can help you study or work. If you have any questions, you can leave a message to communicate.