如何在 iOS11 中禁用对 tableview 单元格的完全滑动

How do I disable the full swipe on a tableview cell in iOS11

UITableViewDelegate.h

// Swipe actions
// These methods supersede -editActionsForRowAtIndexPath: if implemented
// return nil to get the default swipe actions
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);
- (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

但是,我在我的 trailingActions 方法中返回 nil,我仍然可以在我的 tableview 中进行完全滑动以删除。如何防止完全滑动? (我希望用户必须滑动然后按下 "Delete" 按钮。

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    return nil
}

编辑:我在 iOS 11/XCode 9/Swift 4 更新之前实施了 canEditRowAt 并提交了编辑样式。甚至在我实现 trailingSwipeActionsConfigurationForRowAt 之前就启用了完全滑动。

像下面这样实现:

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, sourceView, completionHandler) in
        print("index path of delete: \(indexPath)")
        completionHandler(true)
    }
    let swipeAction = UISwipeActionsConfiguration(actions: [delete])
    swipeAction.performsFirstActionWithFullSwipe = false // This is the line which disables full swipe
    return swipeAction
}

这是禁用完全滑动的行

swipeAction.performsFirstActionWithFullSwipe = false 

如果您实现了 editingStyleeditActionsForRowAt.

之类的功能,请删除其他功能

我可以按照以下答案禁用特定单元格的滑动操作:

您可以 return:

而不是 returning nil
return UISwipeActionsConfiguration.init()