Skip navigation.
 
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
FROM : Shaun Wexler
DATE : Thu Oct 07 18:09:42 2004

On Oct 7, 2004, at 8:57 AM, Gabriele de Simone wrote:

> 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.


How are you going to automatically trigger a change notification for
that key, if you disable automatic notification for the key?!!  Use one
or the other.  It's okay to send your own -rearrangeObjects message in
the setter if you prefer.  Are you just trying to avoid rearranging
unnecessarily, if the setter is called with the same key?  BTW, it
might be better to use isEqualToString: rather than compare pointers,
since you're making a copy.
--
Shaun Wexler
MacFOH
http://www.macfoh.com

Related mailsAuthorDate
mltriggerChangeNotificationsForDependentKey in subclass of NSArrayController Gabriele de Simone Oct 7, 17:57
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Shaun Wexler Oct 7, 18:09
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Gabriele de Simone Oct 7, 19:44
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Shaun Wexler Oct 7, 20:45
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Gabriele de Simone Oct 7, 22:15
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Jacob Lukas Oct 8, 05:33
mlRe: triggerChangeNotificationsForDependentKey in subclass of NSArrayController Steven Kramer Oct 9, 15:46