寫在前面
- 本文使用的IDE為Xcode9.4.1
- 目的是展示在控件TableView加滑動(dòng)按鈕
- 使用的語(yǔ)言為Objective-C
效果如圖:
tableViewSlidButton.png
實(shí)現(xiàn)方式
只需在iOS OC TableView的使用(1)的.m文件中加入代理方法:
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction * Action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按鈕1" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//按鈕1激發(fā)代碼
}];
Action1.backgroundColor = [UIColor redColor];
UITableViewRowAction * Action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按鈕2" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//按鈕2激發(fā)代碼
}];
Action2.backgroundColor = [UIColor greenColor];
UITableViewRowAction * Action3 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"按鈕3" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//按鈕3激發(fā)代碼
}];
Action3.backgroundColor = [UIColor blueColor];
return @[Action1,Action2,Action3];
}