Re: Bindings NSArrayController is changing selectionIndex
Re: Bindings NSArrayController is changing selectionIndex
- Subject: Re: Bindings NSArrayController is changing selectionIndex
- From: Tod Cunningham <email@hidden>
- Date: Mon, 20 Sep 2004 02:25:24 -0400
Scott:
Thanks for your input, and the case you identified would indeed require
a change to the index. However, my sample is just adding to the end of
the list so the selection should never change, but it is. I didn't
think of trying the "selection" object, I will give it a try.
- Tod
On Sep 19, 2004, at 10:14 PM, Scott Stevenson wrote:
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
_______________________________________________
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