• 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: Properties and bindings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Properties and bindings
      • From: mmalc crawford <email@hidden>
References: 
 >Properties and bindings (From: "D.K. Johnston" <email@hidden>)

  • Prev by Date: Re: Converting from Carbon Event Manager to NSTimer
  • Next by Date: Re: Image processing in Cocoa
  • Previous by thread: Re: Properties and bindings
  • Next by thread: Re: Properties and bindings
  • Index(es):
    • Date
    • Thread