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 中进行完全滑动以删除。如何防止完全滑动? (我希望用户必须滑动然后按“删除”按钮。
@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
如果您实现了任何类似 editingStyle
和 editActionsForRowAt
的功能,请删除其他功能。
关于ios - 如何禁用 iOS11 中 tableview 单元格的完全滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46414707/