1

I'm trying to delete a row in t stable view but every time I select delete in the app it crashes with this error

Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), 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).'

Here is how I'm deleting to row.

func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!){

   tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation:UITableViewRowAnimation.Fade)

}
0

1 Answer 1

6

You have to delete the corresponding record in the tableView's datasource as well.

When you delete a row in the table, the resulting count of rows must match. Check your tableView.numberOfRowsInSection

2
  • how do I check the count of the rows when tableView.numberOfRowsInSection is a method requiring and int ' tableView.numberOfRowsInSection(<#section: Int#>)' Aug 11, 2014 at 18:54
  • The section number. If your table contains only one section you don't have to bother with that parameter. If your table contains multiple sections you have to return the number of rows for each section.
    – zisoft
    Aug 11, 2014 at 19:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.