binding 101: controller does not notify?
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