Re: Properties and bindings
Re: Properties and bindings
- Subject: Re: Properties and bindings
- From: "D.K. Johnston" <email@hidden>
- Date: Wed, 24 Sep 2008 16:32:59 -0700
It's working now, but I don't understand why. I've got two objects:
MyController and MyModel. The interesting parts of the headers look
like this:
@interface MyModel : NSObject
{
NSInteger myInteger;
}
@property(assign) NSInteger myInteger;
- (void)changeMyInteger;
@end
@interface MyController : NSObject
{
MyModel *model;
}
@property(assign) MyModel *model;
- (IBAction)buttonClick:(id)sender;
@end
Both properties are synthesized in the implementation files. Here's
what buttonClick: does:
[self.model changeMyInteger];
A MyController instance is in the nib file, and it creates an instance
of MyModel when it awakes. I have a view in the nib with an
NSTextField, which is bound to MyController with the key path
model.myInteger.
I start it up, and the initial value of myInteger (set by MyModel) is
in the textfield. But when I click the button, nothing happens: the
textfield stays the same.
I get buttonClick: to do this instead:
[self willChangeValueForKey:@"model"]; // Thanks Jason!
[model changeMyInteger];
[self didChangeValueForKey:@"model"];
and it works just as it should: the value in the text field changes
when I click the button.
So now I'm trying to understand why the message to self.model won't
work. Doesn't that form do the KVO notification?
I suppose I could just surround everything with willChange... and
didChange...; but I would like to understand what's going on.
dkj
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden