I'm creating an iOS App using Swift 4 and I'm not using Storyboards. To delete a row from the Table View Controller the user swipe left the row and then click the Delete Button.
Here is the code I'm using to implement that (no external libraries have been used):
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
self.isAccessibilityElement = true
self.accessibilityLabel = "Delete row"
let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { (action, view, handler) in
self.removeRowFromMyList(indexPath: indexPath.row)
MyListController.stations.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .automatic)
self.tableView.setEditing(false, animated: true)
self.tableView.reloadData()
}
let swipeAction = UISwipeActionsConfiguration(actions: [deleteAction])
swipeAction.performsFirstActionWithFullSwipe = false
return swipeAction
}
I did check other questions and none of them address that. Please don't hesitate to comment here for any other information you need to know to solve this issue. Thanks :)