views:

47

answers:

1

I'm adding a row like this, when a button is pressed. It must be the very first row in the first section:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

I don't call anything else here. No -reloadData. I keep getting this:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (6) must be equal to the number of rows contained in that section before the update (6), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'

+2  A: 

As the error says, you must insert a row into your data source as well as telling the tableView to animate the new row. In your code (that you haven't posted) you probably have a call to numberOfRowsInSection. At the time of this insertRowsAtIndexPaths call, it should be returning 7 (because you are adding one) but instead it is returning 6.

coneybeare