Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: change in model not reflected in interface



On Jul 30, 2005, at 11:33 AM, mmalcolm crawford wrote:

- (void)didChangeValueForKey:(NSString *)key {
if ( [key isEqualToString:@"foo"] ) {
[self setBar:[self foo] * 2]; // this change is not reflected in the interface???
NSLog(@"%f", [self bar]);
}
}
@end


AFAIK, the object above is KVO complaint. I have an interface with two text fields, one bound to foo and the other bound to bar. When I change the value in the text field bound to foo the value in the text field bound to bar doesn't change.



The accessor methods are KVO compliant, but you disrupt the mechanism by overriding didChangeValueForKey: (specifically, you don't invoke the superclass's implementation

I knew it was something simple, it works if I invoke the superclass' implementation.


-- although you shouldn't be doing this anyway: is there anywhere in the documentation that suggests that overriding the KVO notification methods is a common pattern?).

No, there isn't.

It's not clear why you would do this rather than simply:

- (void)setFoo:(float)value {
    foo = value;
    [self setBar:value * 2];
}

Well, the way I though of it was setFoo: does just that, sets foo, and shouldn't do anything else. I thought didChangeValueForKey: would work like a delegate method. There wasn't anything in the documentation to make me think that, but there wasn't anything to make me think it was the wrong thing to do either. Though, in hindsight it was a silly thing to do.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >change in model not reflected in interface (From: Edward Hillenbrand <email@hidden>)
 >Re: change in model not reflected in interface (From: Scott Quiring <email@hidden>)
 >Re: change in model not reflected in interface (From: mmalcolm crawford <email@hidden>)
 >Re: change in model not reflected in interface (From: Edward Hillenbrand <email@hidden>)
 >Re: change in model not reflected in interface (From: mmalcolm crawford <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.