【问题标题】:How to disable swipe to delete option at UITableView如何在 UITableView 上禁用滑动删除选项
【发布时间】:2017-12-23 14:56:01
【问题描述】:

我在同一个 UIViewController 上有 2 个 UITableView(表 1 和表 2)。我想在我的 Table-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 中的删除编辑选项功能。

请帮忙。提前致谢。

【问题讨论】:

    标签: uitableview swift4 editing


    【解决方案1】:

    你可以使用UITableViewDelegate提供的这个功能:

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    

    只需实现一些逻辑来检查您是否要在给定的indexPath 和给定的tableViewreturn true 上进行编辑,如果您想编辑/删除,则在return false 上进行编辑。

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多