• 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
binding 101: controller does not notify?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

binding 101: controller does not notify?


  • Subject: binding 101: controller does not notify?
  • From: Ondra Cada <email@hidden>
  • Date: Mon, 13 Mar 2006 18:49:50 +0100

Hello,

sorry if this is indeed trivial, but somehow I cannot find an answer...

I've got an NSArrayController subclass, which happens to have a few derived keys. I would bet that if programmed this way, it should work:

@interface MyController:NSArrayController .... @end
@implementation MyController
-(NSString*)displayNameOfCurrent {
return [NSString stringWithFormat:@"%d",[self selectedObjects]]; // just testing, the real case more complex
}
+(void)initialize {
[self setKeys:[NSArray arrayWithObject:@"selectedObjects"] triggerChangeNotificationsForDependentKey:@"displayNameOfCurrent"];
}
@end


Alas it does not--the KVO notification for displayNameOfCurrent is not sent if selection changes.

What obvious thing am I overlooking?!?

Note: at the moment I am using the following work-around which runs well, but is pretty ugly...

-(void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context {
if ([keyPath isEqualToString:@"selectedObjects"]) {
[self willChangeValueForKey:@"displayNameOfCurrent"];
[self didChangeValueForKey:@"displayNameOfCurrent"];
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
-(NSString*)displayNameOfCurrent {
static first=YES;
if (first) {
[self addObserver:self forKeyPath:@"selectedObjects" options: 0 context:NULL];
first=NO;
}
...
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ 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: binding 101: controller does not notify?
      • From: email@hidden
  • Prev by Date: Re: What framework & language is good for an old C++ mule.
  • Next by Date: Re: NSUserDefaults and objects
  • Previous by thread: CoreData: Enumerating through very large data sets?
  • Next by thread: Re: binding 101: controller does not notify?
  • Index(es):
    • Date
    • Thread