我很难让我的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);
...
}码
问题
发布于 2018-02-12 04:21:47
删除单元格的方式是错误的,您应该使用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;
}此外,对于这样一个简单的屏幕,项目过于复杂,请记住更多的代码=更难调试
https://stackoverflow.com/questions/48738937
复制相似问题