如何禁用iOS11中tableview单元格的完全滑动 [英] How do I disable the full swipe on a tableview cell in iOS11
问题描述
UITableViewDelegate.h
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,我仍然可以完全滑动删除我的桌面视图。如何防止完全滑动? (我希望用户必须滑动然后按删除按钮。
However, I am returning nil in my trailingActions method and I still can do a full swipe to delete in my tableview. How can I prevent the full swipe? (I want the user to have to swipe then press the "Delete" button.
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
return nil
}
编辑:在iOS 11 / XCode 9 / Swift 4更新之前,我已经实现了canEditRowAt并提交了编辑样式。甚至在我实现trailingSwipeActionsConfigurationForRowAt之前,已经启用了完全滑动。
I had implemented canEditRowAt and commit Editing style before the iOS 11/XCode 9/Swift 4 update. The full swipe was enabled even BEFORE I implemented the 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
。
And remove the other functions if you implement any like editingStyle
and editActionsForRowAt
.
这篇关于如何禁用iOS11中tableview单元格的完全滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!