简体   繁体   English

如何在iOS中以编程方式取消滑动以删除?

[英]How to programmatically cancel a swipe to delete in iOS?

I have a UITableView which has a swipe to delete action using: 我有一个UITableView,可以使用以下方法轻扫以删除操作:

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)

This works perfectly fine, however there are some situation where the delete should not happen, in this situation when swiping to delete and pressing the delete button the button doesn't disappear but stays there as if nothing is happening. 这完全正常,但是有些情况下不应该删除,在这种情况下,当滑动删除并按下删除按钮时,按钮不会消失,但保持在那里,好像什么也没发生。

It seems to me the delete button only collapses when the row is removed from the table (or its backing store). 在我看来,删除按钮仅在从表(或其后备存储)中删除行时才会折叠。

Is there a way to tell the view to cancel the action? 有没有办法告诉视图取消操作?

Add the logic for determining if the row is eligible for editing to 添加逻辑以确定该行是否有资格进行编辑

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool (from UITableViewDataSource ) func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool (来自UITableViewDataSource

Of course this prevents all editing of the cell not just deleting, this may not be the way to go if you want to allow editing but not deleting. 当然,这会阻止对单元格的所有编辑而不仅仅是删除,如果您想允许编辑但不删除,这可能不是可行的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM