UITableView swipe actions + UITableViewDiffableDataSource

发布
更新
字数 89
阅读 1 分钟
阅读量 680

首先需要子类化 UITableViewDiffableDataSource ,然后在子类中重写 tableView(_, canEditRowAt) -> Bool 方法,返回真值即可。

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    itemIdentifier(for: indexPath) is Todo
}

注意

当代码块只有一行表达式时可以忽略 return 关键字,例如 [1, 2, 3].map { $0 * 2 }这样的写法。