I have problem with reloading my tableview.Then I delete something on my tableview, the tableview should reload and the data should go up.But then I delete something nothing happens and there some blank spaces between the rows. I tried with tableview.deleterows but after I implemented this method my app crashes..
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
if editingStyle == UITableViewCellEditingStyle.delete {
//let mt = movieArray2[indexPath.row]
//1
guard let appDelegate =
UIApplication.shared.delegate as? AppDelegate else {
return
}
let managedContext =
appDelegate.persistentContainer.viewContext
managedContext.delete(self.movieArray2[indexPath.row])
tableView.deleteRows(at: [indexPath], with: .automatic)
do{
try managedContext.save()
} catch {
}
}