Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS11中禁用对tableview单元格的完全滑动_Ios_Uitableview_Swipe_Ios11_Swift4 - Fatal编程技术网

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

如何在iOS11中禁用对tableview单元格的完全滑动,ios,uitableview,swipe,ios11,swift4,Ios,Uitableview,Swipe,Ios11,Swift4,UITableViewDelegate.h // Swipe actions // These methods supersede -editActionsForRowAtIndexPath: if implemented // return nil to get the default swipe actions - (nullable UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeAc

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中执行完全滑动以删除。如何防止完全刷卡?(我希望用户必须刷卡,然后按“删除”按钮

编辑:在iOS 11/XCode 9/Swift 4更新之前,我已经实现了canEditRowAt和commit编辑样式。甚至在我实现TrailingSwipeActionsConfiguration for Rowat之前,就已经启用了完全滑动功能。

实现如下:

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 

如果您实现了任何类似
editingStyle
editActionsForRowAt

的功能,请删除其他功能。我可以通过以下回答禁用特定单元格的滑动操作:

不返回nil,您可以返回:

return UISwipeActionsConfiguration.init()

您在这种情况下使用刷卡操作而不是编辑操作是有原因的吗?编辑操作是从iOS 8.0+开始提供的,而不是仅限于iOS 11.0+,因此将为尚未升级到最新iOS版本的设备提供更大的灵活性。我的意思是,这是一个澄清点,而不是回答您的问题。我ly正在使用编辑操作。我已经实现了canEditRowAt和commit编辑样式。但出于某种原因(甚至在实现trailingSwipeActionsConfigurationForRowAt之前),已启用完全滑动。我正在更新我的问题以包含此内容。我以前在commit editingStyle函数中有一些逻辑。这是否意味着我将该逻辑传输到UIContextualAction的代码块中?这似乎可行,但我想知道这是否是最佳做法。您必须在此处传输此逻辑。我已使用“EditActionsFrrowat”方法在tableview单元格中添加左扫,请说明如何停止此方法中的所有左扫。因为我也用于低于iOS 10.0的设备。?–@ViniApp在这种情况下使用哪行代码“completionHandler(true)”呢?
return UISwipeActionsConfiguration.init()