Skip navigation.
 
mlRe: Keys dependent on NSArrayController's selection
FROM : Dave Dribin
DATE : Thu May 08 20:45:20 2008

On May 8, 2008, at 9:22 AM, Sean McBride wrote:
> On 5/8/08 1:53 AM, Dave Dribin said:

>> For kicks, I did try
>> "peopleController.selectionIndex" as well as
>> "peopleController.selectedObjects" to no avail.

>
> So it seems you have observed the same as I: that
> keyPathsForValuesAffectingValueForKey does not seem to work with key
> paths, despite the docs saying it should.


Yeah, I'm confused.  I think this *should* work.  Is it broken, or are 
the docs just not pointing out a known limitation?

> This is what I was remembering:
> <http://www.cocoabuilder.com/archive/message/cocoa/2006/6/4/164955>


That's pretty clear, and I'm understanding that I *shouldn't* do 
willChange/didChange.  What I'm lacking is information of how to do it 
the "proper" way.  If keyPathsForValuesAffectingValueForKey: is not 
effective, what are my options?

I guess another option is to not use bindings for the button's enabled 
state, and just do it the "old fashioned way" with an outlet to the 
button, along with manual KVO:

- (void)updateButtonEnabled {
    [button setEnabled: self.canEnableButton];
}

- (void) awakeFromNib {
    [peopleController addObserver:self
                        forKeyPath:@"selectionIndexes"
                          options:0
                          context:SelectionIndexesContext];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object 
change:(NSDictionary *)change context:(void *)context
{
    if (context == SelectionIndexesContext)
        [self updateButtonEnabled];
}

-Dave

Related mailsAuthorDate
mlKeys dependent on NSArrayController's selection Dave Dribin May 8, 01:16
mlRe: Keys dependent on NSArrayController's selection Sean McBride May 8, 01:58
mlRe: Keys dependent on NSArrayController's selection Dave Dribin May 8, 08:53
mlRe: Keys dependent on NSArrayController's selection Sean McBride May 8, 16:22
mlRe: Keys dependent on NSArrayController's selection Dave Dribin May 8, 20:45
mlRe: Keys dependent on NSArrayController's selection Sean McBride May 8, 21:02
mlRe: Keys dependent on NSArrayController's selection Hamish Allan Jun 17, 23:26