I have a NSTreeController which array is bound to a "items" (custom) property of an NSArrayController subclass. As the tree controller is not bound to the selection of the NSArrayController I need to make sure to let the tree controller know that items has to be fetched after the selection of the array controller changes.
I have done the following in a subclass of NSArrayController:
+ (NSSet *)keyPathsForValuesAffectingItems
{
return [NSSet setWithObjects:@"selectedObjects",nil];
}
Which should be sufficient AFAIK. The class method is called but does not seems to have any effect.
If I implement an observer for selectedObjects
it works fine:
- (void)awakeFromNib;
{
[self addObserver:self forKeyPath:@"selectedObjects" options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(NSObjectController *)context;
{
if ([keyPath isEqual:@"selectedObjects"]) {
[self willChangeValueForKey:@"items"];
[self didChangeValueForKey:@"items"];
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
Any clue?