oc tableview侧滑按钮自定义

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}
////执行删除操作
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
// NSLog(@"删除删除删除删除删除删除删除删除删除");
//}
////侧滑出现的文字
//- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
// return @"删除";
//}

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 添加一个删除按钮
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self deleteCommodityAction:indexPath.row];
}];
deleteRowAction.backgroundColor = COLOR_RGB(255,88,112);

// 添加一个更多按钮
NSString *str ;
if (_upLoad == 0) {
str = @"下架";
}else {
str = @"上架";
}
UITableViewRowAction *moreRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:str handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// NSLog(@"点击了更多");
[self stateChangeAction:indexPath.row];
}];
moreRowAction.backgroundColor = COLOR_RGB(255, 171, 88);
// moreRowAction.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];

// 将设置好的按钮放到数组中返回
return @[deleteRowAction, moreRowAction];

}