Re: Bindings NSArrayController is changing selectionIndex
Re: Bindings NSArrayController is changing selectionIndex
- Subject: Re: Bindings NSArrayController is changing selectionIndex
- From: Scott Stevenson <email@hidden>
- Date: Sun, 19 Sep 2004 19:14:30 -0700
On Sep 19, 2004, at 4:19 PM, Tod Cunningham wrote:
The array controller is changing the value of its selectionIndex even
though "selects inserted objects" (selectsInsertedObjects) is off. I
setup an observer to watch the controllers selectionIndex and watched
it through an iteration of adding a new object (addObject).
[logArrayController addObserver:self
forKeyPath:@"selectionIndex"
options:
NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld
context:nil];
You really want to put the options in parenthesis (bitwise or):
options: (NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld)
I'm not sure offhand if this is causing your problem with receiving
NSNull for the values.
The method observeValueForKeyPath gets called twice during the
addObject operation:
1. selectionIndex changes to to end of end of the array
2. selectionIndex changes to NSNotFound
Should selectionIndex be changing?
If an object is inserted before the current selection, it seems like
the selectionIndex would have to change because its order in the array
would change. For example, if you had an array that looked like:
Object A
Object C < -- selectionIndex: 1
Object D
Let's say you wanted Object C to remain selected. And you inserted
something like this:
Object A
Object B < -- new object
Object C < -- selectionIndex: 2
Object D
Clearly, the selection index has to change. It might be easier to track
using the "selection" controller key, which is an object, not an int.
- Scott
--
Tree House Ideas
http://treehouseideas.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden