I have a UITableView with a C++ object being the datasource, so there isn't any kind of NSArray. I'm getting a crash whenever I want to insert a row to the end of the existing list
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]
It crashes on [tableView endUpdates]. However I don't have any NSArray or any code calling objectAtIndex in my implementation. I don't know why I'm crashing.
I only have a single section and always add the new row to the end of section 0. The number of rows returned are correct and therefor fully synch.
In the logs I see, [tableView endUpdates] calls to numberOfRowsInSection which correctly returns a count of the previous count plus one. However, it never calls to cellForRowAtIndexPath again and unable to get past [tableView endUpdates];
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"...");
........
NSArray *insertIndexPaths = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:oldCount + i inSection:[indexPath section]], nil];
NSLog(@"Insert: %d %d %d", i, (int) oldCount, (int) newCount);
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int i = _reader->allRead() ? _reader->getWindowCount() : _reader->getWindowCount() + 30;
return i;
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
// return __results__ ? 1 : 0;
}