0

I have a table view cell which should delete the particular table view cell if I swipe but the image is not deleted but the contents in the row except image are deleting.

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == .delete {
            print("Deleted")
            
            name.remove(at: indexPath.row)
            miscellaneousText.remove(at: indexPath.row)
            amount.remove(at: indexPath.row)
            images.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: .fade)
            tableView.reloadRows(at: [indexPath], with: .automatic)
            
            
}
    }
  • 1) Never use multiple arrays for the data source. 2) Never call `reloadRows/reloadData` right after `insertRows/deleteRows`. As the animation parameter implies `insertRows/deleteRows` does update the UI. – vadian May 21 '21 at 06:32
  • 1) Possible duplicate: https://stackoverflow.com/questions/40156274/deleting-a-row-from-a-uitableview-in-swift-3 2) It's better to restructure the code and create an array of objects and then remove the item at indexPath from the array and reload. – Mohamad Kaakati May 21 '21 at 16:26

0 Answers0