I am making a table view and I want to make a function where you can delete a row by swiping right and tapping the delete button. Me and my teacher have tried for about half an
This swift function can delete a row by swiping right and tapping the delete button. Actually this function delete item from items array then delete row. In addition this row removed from tableView
.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == UITableViewCellEditingStyle.delete {
// your items include cell variables
items.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}