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

Re: binding 101: controller does not notify?


  • Subject: Re: binding 101: controller does not notify?
  • From: email@hidden
  • Date: Mon, 13 Mar 2006 13:48:44 -0800


Ondra Cada wrote:

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?!?

Perhaps Implement :

+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key
{
	if ( [key isEqualToString:@"selectedObjects"] )
		return YES;

	return [super automaticallyNotifiesObserversForKey:key];
}

I believe that NSArrayController does not automatically notify for some keys by default, so you have to set this up manually. (I know this is true for arrangedObjects)

Good Luck

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

Andre email@hidden



_______________________________________________
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: Ondra Cada <email@hidden>
References: 
 >binding 101: controller does not notify? (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Xcode won't compile a Universal Binary
  • Next by Date: Can I have two modal windows?
  • Previous by thread: binding 101: controller does not notify?
  • Next by thread: Re: binding 101: controller does not notify?
  • Index(es):
    • Date
    • Thread