[TABEL VIEW] Add, Delete Row and value in UItabelView






This is a continuation of Insert and delete tabel, but now I added a way to DELETE value in tableview, if not read the previous prosess klik this link

Next step in UITableViewCellEditingStyle you add this code :

  sum -= Int(List[indexPath.row])!
  labelRp.text = "Rp \(sum)"

we need to add the functionality to delete a row from the Table View with the tableView:commitEditingStyle:forRowAtIndexPath: methodlike this code below.


func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { sum -= Int(List[indexPath.row])! labelRp.text = "Rp \(sum)" List.remove(at: indexPath.row) tableView.beginUpdates() tableView.deleteRows(at: [indexPath], with: .automatic) tableView.endUpdates() } }

which will delete the selected data,  before could remove row only
note: use this (+=) for added operators and use (-=) for subtraction


No comments: