Remove action on NSArrayController bound to table causes index beyond bounds
Remove action on NSArrayController bound to table causes index beyond bounds
- Subject: Remove action on NSArrayController bound to table causes index beyond bounds
- From: Luke Evans <email@hidden>
- Date: Mon, 23 Mar 2009 16:52:51 -0700
I have a table bound to an NSArrayController that provides content
from Core Data.
This has been pretty trouble-free except that the hook up that removes
the selected object/row (currently a 'minus' button under the table
that uses the "remove" action on the controller) appears to cause an
exception intermittently.
The problem manifests as an index out of bounds exception (and often a
subsequent CoreData error, though I think this is likely a knock-on
effect).
*** -[NSCFArray objectAtIndex:]: index (8) beyond bounds (8)
2009-03-23 16:17:46.118 App[17940:817] *** -[NSCFArray
objectAtIndex:]: index (8) beyond bounds (8)
2009-03-23 16:17:46.132 App[17940:817] CoreData could not fulfill a
fault for '0x1a57a90 <x-coredata://BD1062B2-D44E-478E-8FBD-B6C62B95575F/MyManagedObject/p558
>
Here's the stack trace at the point the exception is raised, with the
array controller's 'remove' still visible at the bottom.
#0 0x93ed2c26 in -[NSException raise]
#1 0x964f7571 in -[NSTableBinder _updateSelectionIndexes:]
#2 0x964f6caf in -[NSTableBinder
_observeValueForKeyPath:ofObject:context:]
#3 0x964f69a9 in -[NSTableBinder
observeValueForKeyPath:ofObject:change:context:]
#4 0x94f66b0e in NSKVONotify
#5 0x94ef70a5 in -[NSObject(NSKeyValueObservingPrivate)
_notifyObserversForKeyPath:change:]
#6 0x962d570a in -[NSController _notifyObserversForKeyPath:change:]
#7 0x962d560b in -[NSController didChangeValueForKey:]
#8 0x964f1920 in -[NSArrayController
didChangeValuesForArrangedKeys:objectKeys:indexKeys:]
#9 0x96690bb6 in -[NSArrayController
_removeObjectAtArrangedObjectIndex:objectHandler:]
#10 0x9668cd95 in -[NSArrayController
removeObjectAtArrangedObjectIndex:]
#11 0x9668d4ff in -[NSArrayController remove:]
...
Now, the circumstance in which this occurs _appears_ to involve a
boundary condition. If the deletion of the row is just about to cause
the number of items in the table to fit vertically in the view (i.e.
vertical scroll bar will disappear), then the exception can occur. I
need to continue testing, but at the moment I'm confident in saying
that this is a strong correlation. It may be causation.
In the absence of this condition I appear to be able to add and delete
items/rows quite happily using the array controller actions.
At present, the array controller is configured for single selection
and to preserve selection (I have tried turning the latter off, to no
effect).
I think I've seen some discussion in the list archives that may be
related (index out of bounds when removing from a table), but I
haven't read anything that gives me a bead on what to investigate next.
Does anyone recognise these set of circumstances, or have any insight
to why NSTableBinder's _updateSelectionIndexes might be getting
upset? When the problem is not induced, the selected row correctly
disappears and the table is left with no selection (which is allowed/
intended), so I'm not sure why the apparent reconfiguration of the
view in its scroll view would have any different effect. However, as
a rough guess it looks like something hasn't been updated with the new
extent of the row indices in this case.
-- Luke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden