• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController


  • Subject: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • From: Gabriele de Simone <email@hidden>
  • Date: Thu, 7 Oct 2004 13:44:11 -0400

On Oct 7, 2004, at 12:09 PM, Shaun Wexler wrote:

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,

I think you are misunderstanding what automaticallyNotifiesObserversForKey: does. If you return NO, you are just declaring the intention to call willChangeValueForKey: and didChangeValueForKey: yourself (which is what I am doing in the example). Even if I change my code to return YES for myKey (from automaticallyNotifiesObserversForKey: of course), the notification for the dependent key is not sent.

Again, the point of the question is not that I don't want to call rearrangeObjects, but to understand why the notification is not being triggered.

Gabe

_______________________________________________
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
  • Follow-Ups:
    • Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
      • From: Shaun Wexler <email@hidden>
References: 
 >triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Gabriele de Simone <email@hidden>)
 >Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController (From: Shaun Wexler <email@hidden>)

  • Prev by Date: Memory management and Objects.(Newbie)
  • Next by Date: Re: Selection and insertion point handling w/ NSTextAttachments
  • Previous by thread: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • Next by thread: Re: triggerChangeNotificationsForDependentKey in subclass of NSArrayController
  • Index(es):
    • Date
    • Thread