如何在UITableView中禁用“刷卡删除”选项

如何在UITableView中禁用“刷卡删除”选项,uitableview,swift4,editing,Uitableview,Swift4,Editing,我在同一UIViewController中有2个UITableView表1和表2。我想在我的表2中编辑功能 我在视图控制器中添加了tableview数据源方法,如下所述:- func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete {

我在同一UIViewController中有2个UITableView表1和表2。我想在我的表2中编辑功能

我在视图控制器中添加了tableview数据源方法,如下所述:-

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {

            tableView.beginUpdates()
            myArray.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .fade)
            tableView.endUpdates()
        }
    } 
两个tableview都调用此方法。因此,每个tableview单元格都可以打开删除选项

但是我只想在表2中使用这个删除编辑选项。我想限制表1中的删除编辑选项功能


请帮忙。提前感谢。

您可以使用UITableViewDelegate提供的此功能:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}
只需实现一些逻辑来检查是否允许在给定的indexPath和给定的tableView上进行编辑,如果需要编辑/删除,则返回true;如果不需要,则返回false

希望这有帮助