I have some tableview cells with some data on them and the cells have a cross button on them (at the top right) on the click of which the cell should get deleted. This is how I'm trying to delete...
extension sellTableViewController: imageDelegate {
func delete(cell: sellTableViewCell) {
if let indexPath = tableview?.indexPath(for: cell) {
//1.Delete photo from datasource
arrProduct?.remove(at: indexPath.row)
print(self.appDelegate.commonArrForselectedItems)
tableview.deleteRows(at: [indexPath], with: .fade)
}
}
}
But when I click on the cross button I get an error message saying The number of sections contained in the table view after the update (1) must be equal to the number of sections contained in the table view before the update (2), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
My tableview numberOfSections
and numberOfRowsInSection
is given as follows...
func numberOfSections(in tableView: UITableView) -> Int {
return (arrProduct?.count)!
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let product = arrProduct![section]
return product.images.count
}
Hope somebody can help...