From 9f98e172b64421a3f4b9ed1544f6afdd0f523722 Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Thu, 1 Nov 2018 23:04:56 +0530 Subject: [PATCH] Tunnels list: Swipe left to delete --- .../UI/iOS/TunnelsListTableViewController.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift index d142ea4..67ed4f5 100644 --- a/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift @@ -273,6 +273,23 @@ extension TunnelsListTableViewController { let tunnelDetailNC = UINavigationController(rootViewController: tunnelDetailVC) showDetailViewController(tunnelDetailNC, sender: self) // Shall get propagated up to the split-vc } + + override func tableView(_ tableView: UITableView, + trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + let deleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: { [weak self] (_, _, completionHandler) in + guard let tunnelsManager = self?.tunnelsManager else { return } + let tunnel = tunnelsManager.tunnel(at: indexPath.row) + tunnelsManager.remove(tunnel: tunnel, completionHandler: { (error) in + if (error != nil) { + ErrorPresenter.showErrorAlert(error: error!, from: self) + completionHandler(false) + } else { + completionHandler(true) + } + }) + }) + return UISwipeActionsConfiguration(actions: [deleteAction]) + } } // MARK: TunnelsManagerDelegate