Section Index leads to UI Table View Array index out of bounds
I created a Controller managing a UITableView. In order to support Section Indexes (right hand vertical bar of A to Z shortcuts) I enabled sections in the UITableView. In addition I want to be able to use the Edit Button (Top Right) to create a temporary 'Add Record' row. As long as there is only one section an empty table does not cause any problems. As soon as the sections are enabled the application will thrown an exception that an NSArray is empty during the insert of the temporary row (actually during the endUpdates call).
I made sure that my numberOfSections returns 1 and that my numberOfRowsInSection returns one more than what I have in my Core Data DB. Because there is a lot of code involved I am not posting it yet here but this is the exception I get in the console:
2010-09-10 21:55:53.611 iInventory[9085:207] BTC.numberOfRowsInSection(), section: 0, return this row count: 0, editing: 0
2010-09-10 21:55:53.611 iInventory[9085:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableView.m:920
2010-09-10 21:55:53.613 iInventory[9085:207] *** 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 (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted).'
*** Call stack at first throw:
(
0 CoreFoundation 0x02672b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027c240e objc_exception_throw + 47
2 CoreFoundation 0x0262b238 +[NSException raise:format:arguments:] + 136
3 Foundation 0x000cbe37 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:descr iption:] + 116
4 UIKit 0x0034bd37 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 8719
5 UIKit 0x0033b54f -[UITableView insertRowsAtIndexPaths:withRowAnimation:] + 56
6 iInventory 0x0000852e -[BaseTableInsideAViewController setEditing:animated:] + 416
7 UIKit 0x003775b6 -[UIViewController(UINavigationControllerItem) _toggleEditing:] + 77
8 UIKit 0x002d17f8 -[UIApplication sendAction:to:from:forEvent:] + 119
For now I am looking for pointers on how to go ahead. This is especially strange because I only change the sectionNameKeyPath when I create the FetchResultController:
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:[self managedObjectContext]
// sectionNameKeyPath:@"name"
// No section support for now
sectionNameKeyPath:sectionIndexColumnName
cacheName:detailEntityName
];
If I set this one to 'nil' then it works like a charm.
Thanks - Andy
|