Reputation: 5153
I am having trouble getting my UITableView to exit edit mode. Here is how I enter & exit edit mode, see links below for source -
Enter Edit Mode
DbgTableViewHandler.swift(126):
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
...
table.setEditing(true, animated: true);
...
}
Leave Edit Mode
DbgTableView.swift(105):
func removeCell(_ index : Int) {
...
setEditing(false, animated: true);
...
}
Code
Question
Upvotes: 0
Views: 1157
Reputation: 9943
The way you are removing cell is wrong, you should remove it by using deleteRows
way, not remove from the dataSource
then reload table, replace it with this code below and it will work
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;
}
Also your project is over complicated for such a simple screen, remember more code = harder to debug
Upvotes: 3