I am reworking Apple's CoreDataBooks sample iPhone application to add five relationship-less instances of an NSManagedObject class ("Book").
When I add these to a secondary managed object context (MOC) and then  
merge these changes with the primary MOC, the application crashes with  
the following error:
	2009-10-13 02:59:12.787 MyApp[43049:207] *** Terminating app due to  
uncaught exception 'NSRangeException', reason: '*** -[NSCFArray  
objectAtIndex:]: index (7) beyond bounds (7)'
If I reopen the application, those five instances are in the data  
store and are displayed properly in the table view. As they are being  
added to the Core Data store, it looks like there is something wrong  
with the table view update process.
If I wipe the application and recompile, I get the same symptom.

If I first comment out the following line:

[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
in the NSFetchedResultController delegate method:

        -controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:

then the application does not crash on the first insert. But it crashes on a subsequent insert attempts with the following error:
	2009-10-13 03:10:19.072 MyApp[43129:207] *** Assertion failure in - 
[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/ 
UIKit-984.38/UITableView.m:774
	2009-10-13 03:10:19.073 MyApp[43129: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 (2) must be  
equal to the number of rows contained in that section before the  
update (1), plus or minus the number of rows inserted or deleted from  
that section (0 inserted, 0 deleted).'
In this subsequent attempt, I am not adding any Book MOs to the  
secondary MOC, but the table view is still being refreshed. I suspect  
this is because  -insertRowsAtIndexPaths:withRowAnimation: was  
commented out, but strangely the table view has the two rows in the  
first section.
Is there a bug with the -insertRowsAtIndexPaths:withRowAnimation: call  
on the first insert attempt? Is there a way to work around this?
Is there a relatively bug-free demonstration or explanation of how to  
use the NSFetchedResultController class to manage iPhone table view  
updates properly?
Thanks,
Alex
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to