Re: NSArrayController selection bug?
Re: NSArrayController selection bug?
- Subject: Re: NSArrayController selection bug?
- From: mmalcolm crawford <email@hidden>
- Date: Mon, 10 Nov 2003 14:02:00 -0800
On Nov 10, 2003, at 12:12 PM, Jesse Grosjean wrote:
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.
As far as I'm aware (**although this is the subject of some debate, for
which I'm awaiting resolution**) this isn't a bug.
The array itself is not observed, so you're changing the array behind
the controller's back. Granted you're calling setContentArray, but
you're passing in the same object, so I'd guess that there's some
optimisation to ensure no notification is sent. The appropriate thing
to do is either to send a message to the controller (which seems like a
fairly logical thing to do since it's managing the display...?) or
implement the mutable array accessors and call
removeObjectFromContentArrayAtIndex: [The principle is that the
standard accessors are considered to be for immutable data types (to
preserve encapsulation).]
<
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueCoding/Concepts/AccessorConventions.html>;
- (unsigned int)countOf<Key>;
- (id)objectIn<Key>AtIndex:(unsigned int)index;
- (void)insertObject:(id)anObject in<Key>AtIndex:(unsigned int)index;
- (void)removeObjectFrom<Key>AtIndex:(unsigned int)index;
- (void)replaceObjectIn<Key>AtIndex:withObject:
I've put an example of the different cases at:
http://homepage.mac.com/mmalc/CocoaExamples/AddBehindTheScenes.zip
mmalc
_______________________________________________
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.