Thank you for enjoying Designers.how!
Please enter your email address to unlock the rest of this episode.
Don't want to see this? Become a Designers.how member now.
Please enter your email address to unlock the rest of this episode.
Don't want to see this? Become a Designers.how member now.
Deleting a cell from the list is pretty easy. To enable deletion of tableview cells, you just need to implement one function in the SavedLocationsVC
:
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
// delete cell
if editingStyle == .delete {
savedLocations.remove(at: indexPath.row)
tableView.reloadData()
}
}
Upon adding that, you'll be able to swipe to delete. Basically the function checks that we're trying to delete the cell, then removes it from the array of saved locations. After doing so, reloading the table data visually removes it from the list.
The final step in this lesson is to remove the selection highlight from the tableview cells, since we'll be using selection (tap) as our action trigger.