iOS OC TableView的使用(2)-加滑动按钮

写在前面

  • 本文使用的IDE为Xcode9.4.1
  • 目的是展示在控件TableView加滑动按钮
  • 使用的语言为Objective-C

效果如图:

iOS OC TableView的使用(2)-加滑动按钮_第1张图片
tableViewSlidButton.png

实现方式

只需在iOS OC TableView的使用(1)的.m文件中加入代理方法:

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewRowAction * Action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按钮1" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //按钮1激发代码
    }];
    Action1.backgroundColor = [UIColor redColor];
    
    UITableViewRowAction * Action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按钮2" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //按钮2激发代码
    }];
    Action2.backgroundColor = [UIColor greenColor];
    
    UITableViewRowAction * Action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按钮3" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        //按钮3激发代码
    }];
    Action3.backgroundColor = [UIColor blueColor];
    
    return @[Action1,Action2,Action3];
}

你可能感兴趣的:(iOS OC TableView的使用(2)-加滑动按钮)