The problem I'm seeing is that when I create a UIContextualAction
with .destructive
and pass true
in completionHandler
there seems to be a default action for removing the row.
If you create a new Master-Detail App from Xcode's templates and add this code in MasterViewController
...
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let testAction = UIContextualAction(style: .destructive, title: "Test") { (_, _, completionHandler) in
print("test")
completionHandler(true)
}
return UISwipeActionsConfiguration(actions: [testAction])
}
the row you swipe will be removed. Notice that there's no code there updating the table view. Also the model is not updated and if you scroll way up to cause the row to be reloaded it will reappear.
Passing false
in this case does not remove the row. Or using the .normal
style and true
also does not remove the row.
.destructive
and true
results in the row being removed by default.
Can anyone explain this behaviour? Why is the row being removed?