NSArrayController selection bug?
NSArrayController selection bug?
- Subject: NSArrayController selection bug?
- From: Jesse Grosjean <email@hidden>
- Date: Mon, 10 Nov 2003 15:12:26 -0500
I have an NSArrayController that is bound to a NSMutableArray in my
model. And I have a NSTableView that's bounds to this
NSArrayController. Everything is working and seems to be set up
correctly for the basic cases.
But an exception is thrown when the last item in the table view is
selected and I remove an item from my model's mutable array directly
(but in a KVC compliant way), instead of going through the
NSArrayControllers "remove" action. You can duplicate the problem by
adding the following method to the MyDocument class that comes with the
ControllerPlay example program that ships with 10.3. And then connect a
button action to it.
- (IBAction)modelRemove:(id)sender {
NSMutableArray *c = [self contentArray];
[c removeObjectAtIndex:0];
[self setContentArray:c];
}
Run the example. Insert an item or two into the table, and then after
making sure that the last item is selected click your new "remove from
model" button and you will get the error.
What I think is happening is that when the NSArrayController gets the
KVO notification that the array has changed it calls "selectedObjects"
in itself. And it uses it's stored "_selectedIndexes" to find those
objects, but unfortunately the "_selectedIndexes" variable still
contains the index of the last selected object in the table view (that
is now removed), and so when it asks for this index from the model
array it overruns the array.
Is this a known bug? Does anyone have an idea for a workaround? Or am I
just doing something wrong? I wish to implement undo in my model
objects, and so I can't always call NSControllers "remove" command.
Thanks,
Jesse
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.