I have a very weird issue using the iOS 11 SDK.
When setting the
editing
false
true
false
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell!
cell.textLabel?.text = animals[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
tableView.deleteRows(at: [indexPath], with: .fade)
endEditingMode()
}
}
func endEditingMode() {
tableView.setEditing(false, animated: true)
// Here we expect `isEditing = false` since it is set the line before but it is still `true` on iOS 11 devices
// On <= iOS 10 devices however its `false`
print(tableView.isEditing)
}
I had similar problem and tried to solve it with delayed dispatch to the main thread and kept on reducing time to see if it makes sense. I have ended up having this:
DispatchQueue.main.async(execute: {
self.tableView.setEditing(false, animated: true)
})
Solves the issue though you have a little weird delete animation afterwards, presumably due to the fact of the switching state of the tableView and some internal race condition in iOS 11 SDK.