"The number of lines contained in an existing section after the update (1) must be equal to the number of lines contained in this section before the update (1), plus or minus the number of inserted rows or removed from this section (inserted 0, 1 deleted). ''
The error clearly says what is wrong. I would consider your numberOfRowsInSection method. You need to consider the row to be deleted. You cannot always return the same number of rows. If you delete one row from the table, your OffRowsInSection number should return the old return value minus 1.
For instance:
Let's say I use an array of strings to populate a tableview;
In my method numberOfRowsInSection will be used
return [array count];
The cellForRowAtIndexPath method will use
cell.textLabel.text = (NSString*)[array objectAtIndex:indexPath.row];
When I delete a row (e.g. row number 3) from tableView, I also delete the object from the array:
[array removeObjectAtIndex:3]
This way, when numberOfRowsInSection is called again, the array is less than one object, and numberOfRowsInSection returns one number less than before, which takes into account the deleted row.
source share