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)

}
user3847060
  • 141
  • 2
  • 7

1 Answers1

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

zisoft
  • 22,770
  • 10
  • 62
  • 73
  • how do I check the count of the rows when tableView.numberOfRowsInSection is a method requiring and int ' tableView.numberOfRowsInSection(<#section: Int#>)' – user3847060 Aug 11 '14 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 '14 at 19:48