[英]How to disable delete by swipe on destructive UITableViewRowAction?
How to disable swipe left triggering deleteAction?如何禁用向左滑动触发deleteAction? I need it to be invoked only by tapping delete button.我只需要通过点击删除按钮来调用它。
I have this code for providing actions.我有这个代码来提供操作。
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: .destructive, title: "Delete", handler: { _, indexPath in
tableView.beginUpdates()
tableView.deleteRows(at: [indexPath], with: .left)
tableView.endUpdates()
})
return [deleteAction]
}
Tried this fix but it didn't work.尝试了此修复程序,但没有成功。
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
if tableView.isEditing {
return .delete
}
return .none
}
Found the solution.找到了解决方案。 I used trailingSwipeActionsConfigurationForRowAt
method instead of editActionsForRowAt
and there is a property performsFirstActionWithFullSwipe
on a UISwipeActionsConfiguration
which can be disabled.我使用trailingSwipeActionsConfigurationForRowAt
方法而不是editActionsForRowAt
并且performsFirstActionWithFullSwipe
上有一个属性UISwipeActionsConfiguration
可以禁用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.