gpt4 book ai didi

ios - UITableView 禁用滑动以快速删除特定单元格

转载 作者:搜寻专家 更新时间:2023-10-30 22:05:44 26 4
gpt4 key购买 nike

我正在尝试禁用滑动以删除 TableView 中某些特定单元格的操作。但我无法 swift 找到一个好的解决方案。当覆盖“tableView.isEditing = true”方法时,我不希望单元格上的左侧减号。这是我的代码。下面的代码不会禁用滑动到 statusId 为“12”的单元格。希望你能理解我的问题。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath) as! TableViewDateCell
cell.titleStatus.text = mainList[indexPath.row].statusName
//tableView.isEditing = true
//disable swipe to delete for cell with statusId == "12"
if mainList[indexPath.row].statusId == "12" {
//tableView.isEditing = false
cell.selectionStyle = UITableViewCellSelectionStyle.gray
cell.isUserInteractionEnabled = false

}
}


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

}

最佳答案

您可以自定义 UITableViewDelegate 的函数 editingStyleForRowAt,尤其是在不需要滑动时返回 UITableViewCellEditingStyle.none,例如:

public func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle
{
if mainList[indexPath.row].statusId == "12" {
return UITableViewCellEditingStyle.none
} else {
return UITableViewCellEditingStyle.delete
}
}

关于ios - UITableView 禁用滑动以快速删除特定单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49063639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com