当左侧将一个tableview单元格滑动到手机的左边缘时,它会自动触发删除UITableViewRowAction,如何禁用此功能?

时间:2018-01-06 10:16:01

标签: ios uitableview uitableviewrowaction

当向左滑动一个tableview单元格到手机的左边缘时,它会自动触发删除UITableViewRowAction,如何禁用此功能? enter image description here

1 个答案:

答案 0 :(得分:0)

在ios11上,滑动操作在委托方法中定义:

-(UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(11_0){
    UIContextualAction *deleteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:@"哈喽" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
        NSLog(@"hello");
        completionHandler(YES);
    }];
    UISwipeActionsConfiguration *config = [UISwipeActionsConfiguration configurationWithActions:@[deleteAction]];
    config.performsFirstActionWithFullSwipe = NO;//this line will disable auto trigger the action when perform full swipe
        return config;
}

如果这个委托方法没有被激活,它将使用

-(NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 

自动触发操作由 UISwipeActionsConfiguration的performFirstActionWithFullSwipe 确定,因此只需将此值设置为false