iOS developed UITableView left slide delete and other custom functions

  • 2020-11-20 06:16:15
  • OfStack

preface

I believe every iOS developer knows that UITableView's left-slider delete feature is very cool. Sometimes left-slider requires more than one delete feature, and sometimes there are other features such as top slider. In this case, we need to customize our left-slider

The sample code


-(NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
 
 UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                   title:@" Cancel the collection " handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                    NSLog(@" Favorite Click event ");
                    
                   }];
  
 UITableViewRowAction *rowAction2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault
                   title:@" overhead " handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
                    NSLog(@" Top button click event ");
                    
                   }];
 
 rowAction.backgroundColor =RGB(215, 59, 16);
  
 NSArray *arr = @[rowAction,rowAction2];
 return arr;
}

conclusion

We can use UITableViewRowAction to create objects, the following code block is the method executed after clicking, the created objects are added to the array, so we can customize at will, we can also choose the color, very convenient. The above is the whole content of this article, I hope to bring 1 definite help to your study or work, if you have any questions, you can leave a message to communicate.


Related articles: