0

In my TableViewController I get the following error:

Fatal Exception: NSInternalInconsistencyException Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (500) must be equal to the number of rows contained in that section before the update (459), plus or minus the number of rows inserted or deleted from that section (1 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).

Now, this issue has been brought up in a number of cases here on SO, but since I'm not the least bit experienced with objective-c I find it hard to apply to my own code.

There's a tread here: Error 'Invalid update: invalid number of rows in section 0' attempting to delete row in table

and here for example: 'Invalid update: invalid number of rows in section 0

Now my own code looks like this:

-(void)updateContactsStatusOnMainThread:(NSArray*)rowsToReload{

    if([sectionsArray count] > 0 && [sectionsArraySAEs count] > 0){
        //It crashes on the line below
        [self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];  
    }
}

Having read similar threads, I still can't seem to understand what I'm supposed to do. Could someone point me in the right direction. I do understand the problem, as the error message is easy enough to follow. But how does it apply to my code? Does this concern sectionsArray and sectionsArraySAEs and how do I stop the error from happen?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Whipper Snapper
  • 185
  • 2
  • 11

1 Answers1

1

I assume you inserted some rows in to your tableView, but forget to add them in to your dataSource (sectionsArray or sectionsArraySAEs or some other).

First add item in to dataSource, then - insert row in to tableview.

Mike
  • 51
  • 1
  • 8