我在同一个UIViewController上有2个UITableView(Table-1& Table-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单元格都可以打开删除选项。
但我只想在Table-2中使用这个删除编辑选项。我想限制表-1中的删除编辑选项功能。
请帮忙。提前谢谢。
答案 0 :(得分:1)
您可以使用UITableViewDelegate提供的此功能:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
如果你想要编辑/删除,只需实现一些逻辑来检查你是否允许在给定indexPath
和给定tableView
和return true
进行编辑,如果你想要return false
别'吨
希望这有帮助!