Skip navigation.
 
mltriggerChangeNotificationsForDependentKey in subclass of NSArrayController
FROM : Gabriele de Simone
DATE : Thu Oct 07 17:57:39 2004

Esteemed members of the Cocoa Bindings cult,

It seems that if I add a new key to an NSArrayController and make
"arrangedObjects" dependent on that key, the change notifications when
the key is modified are never sent (or at least my views dependent on
"arrangedObjects" don't get updated). Here's the scenario:

+ (void) initialize {
    [self exposeBinding:@"myKey"];
   [self setKeys:[NSArray arrayWithObjects:@"myKey", nil]
  triggerChangeNotificationsForDependentKey:@"arrangedObjects"];
}

+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {

    if ([key isEqualToString:@"myKey"]) {
        return NO;
    }

    return [super automaticallyNotifiesObserversForKey:key];
}

- (void) setMyKey:(NSString*)myKey {
   
    if (_myKey != myKey) {
       [self willChangeValueForKey:@"myKey"];
        _myKey = [myKey copy];
       [self didChangeValueForKey:@"myKey"];
    }
}

The obvious solution is to call [self rearrangeObjects] in the setter
method, but I am more interested in knowing whether I have
misunderstood/ignored some properties of NSControllers.

Thanks,
Gabriele