I've added a swipe to delete functionality with the use of
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath)
-> UISwipeActionsConfiguration?
I'm calling an alert with dismiss/confirm actions. Once dismissed I want to dismiss the swipe action menu.
override func tableView(_ tableView: UITableView,
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteClosure:UIContextualAction.Handler = {
(action:UIContextualAction,
view:UIView,
completionHandler:(Bool) -> Void) in
let alert = self.confirmDeletion({ _ in
let row = indexPath.row;
let removed = self.logList.remove(at: row);
self.deleteLogEntry(removed);
//
tableView.reloadData();
//
}, declineBlock: {_ in
tableView.reloadData();// this hides it but w/o animation
});
DispatchQueue.main.async {
self.present(alert, animated: true, completion: nil);
}
}
let deleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: deleteClosure);
return UISwipeActionsConfiguration(actions: [deleteAction]);
}
So far I've found that reloading table data will close the trailing swipe menu but w/o animation which looks odd. Is there a way to tell it to dismiss with an animation?
** Note about duplicate ** Marked as duplicate to the question that refers to dismiss not working as expected AFTER row was deleted, it is not the case here. I want to dismiss trailing swipe when user cancels deleting and row is NOT removed.
What I've already tried:
tableView.setEditing(false, animated: true);
- no visible differencetableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.automatic);
- row was moved right with animation but the button was overlappingtableView.resignFirstResponder();
- no visible difference (I had to try)tableView.reloadTable()
- swipe menu IS dismissed but w/o animation effect