On Oct 15, 2008, at 22:13, Chris Idou wrote:
@class Class1; @interface Class2 : NSObject { IBOutlet Class1 *class1;} @property(readonly) Class1 *class1; -(BOOL)myMethod; @end #import "Class2.h" #import "Class1.h" @implementation Class2 @synthesize class1; ... - (void)awakeFromNib { [self addObserver:self forKeyPath:@"myMethod" options:NSKeyValueObservingOptionNew context: [Class2 class]]; } + (NSSet *)keyPathsForValuesAffectingMyMethod { NSLog(@"keyPathsForValuesAffectingMyMethod"); return [NSSet setWithObject:@"class1.canLink"]; }
I think your problem is that Class2 isn't properly KVO compliant for the key "class1". Consider what happens when your nib is loaded. At some point, the nib loader needs to set "class1" to its correct value. Since the property is readonly and synthesized, there's no setter method, so the instance variable is changed directly. (I'm going from memory here, but I believe that's what documented to happen.) That presumably fails to trigger any KVO notifications, and your "keyPathsForValuesAffectingMyMethod" is not consulted.
Try this:
...
@interface Class2 ()
@property(readwrite) Class1 *class1; @end
@implementation Class2 @synthesize class1; ....
If my theory is correct, that should cause the outlet to be set via a KVC-compliant setter, and the keypath dependency should start working.
_______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
