gpt4 book ai didi

ios - UITableView.setEditing() 无法禁用编辑模式

转载 作者:行者123 更新时间:2023-11-28 10:45:19 25 4
gpt4 key购买 nike

我无法让我的 UITableView 退出编辑模式。这是我进入和退出编辑模式的方式,请参阅下面的链接以获取源代码-

进入编辑模式

DbgTableViewHandler.swift(126):

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
...
table.setEditing(true, animated: true);
...
}

离开编辑模式

DbgTableView.swift(105):

    func removeCell(_ index : Int) {
...
setEditing(false, animated: true);
...
}

代码

问题

  • 如何让示例中的表格退出编辑模式?

最佳答案

你删除单元格的方式是错误的,你应该使用deleteRows方式删除它,而不是从dataSource中删除然后重新加载表,用下面的代码替换它它将起作用

func removeCell(_ index : Int) {
beginUpdates()
myDbgCells.remove(at: index);
let i = IndexPath(row: index, section: 0)
deleteRows(at: [i], with: .automatic)
endUpdates()

//turn mode off (just cause, for demo's sake)
setEditing(false, animated: true);

print("DbgTableView.removeCell(): cell removed");

return;
}

此外,对于如此简单的屏幕,您的项目过于复杂,记住更多代码 = 更难调试

关于ios - UITableView.setEditing() 无法禁用编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48738937/

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