Ios UITableView.setEditing()无法禁用编辑模式
我无法让UITableView退出编辑模式。以下是我如何进入和退出编辑模式,请参阅下面的链接了解源代码- 进入编辑模式 DbgTableViewHandler.swift(126): 离开编辑模式 DbgTableView.swift(105): 代码Ios UITableView.setEditing()无法禁用编辑模式,ios,swift,uitableview,Ios,Swift,Uitableview,我无法让UITableView退出编辑模式。以下是我如何进入和退出编辑模式,请参阅下面的链接了解源代码- 进入编辑模式 DbgTableViewHandler.swift(126): 离开编辑模式 DbgTableView.swift(105): 代码 问题 如何使示例中的表退出编辑模式 您删除单元格的方式是错误的,您应该使用deleteRows方式将其删除,而不是从数据源中删除,然后重新加载表格,用下面的代码替换它,它就会工作 func removeCell(_ index :
- 如何使示例中的表退出编辑模式
deleteRows
方式将其删除,而不是从数据源中删除,然后重新加载表格,用下面的代码替换它,它就会工作
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;
}
此外,对于这样一个简单的屏幕,您的项目过于复杂,请记住,代码越多=调试难度越大删除单元格的方式是错误的,您应该使用deleteRows
方式将其删除,而不是从数据源中删除
然后重新加载表,用下面的代码替换它,这样就可以工作了
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;
}
此外,对于这样一个简单的屏幕,您的项目过于复杂,请记住更多代码=更难调试我发布了许多文件,希望这是有用的。让我知道如果发布或澄清还需要什么,我已经发布了很多文件,希望这是有用的。让我知道,如果发布或澄清还需要什么,我的天哪,这是有效的。Tj3n,谢谢!!我从来没想过我的问题是细胞移除,太棒了哇!谈论今晚带着微笑上床睡觉的事,谢谢!天哪,这管用。Tj3n,谢谢!!我从来没想过我的问题是细胞移除,太棒了哇!谈论今晚带着微笑上床睡觉的事,谢谢!
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;
}