how to properly use insertRowsAtIndexPaths?

It’s a two step process:

First update your data source so numberOfRowsInSection and cellForRowAtIndexPath will return the correct values for your post-insert data. You must do this before you insert or delete rows or you will see the “invalid number of rows” error that you’re getting.

Then insert your row:

[tblSimpleTable beginUpdates];
[tblSimpleTable insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationRight];
[tblSimpleTable endUpdates];

Simply inserting or deleting a row doesn’t change your data source; you have to do that yourself.

Leave a Comment