On Aug 22, 2009, at 16:16, Michael de Haan wrote:

I wonder if someone can just point me in the correct direction. I am at the stage of not really knowing if the error is simply a missed connection, etc or a fundamental misunderstanding.

Fundamental misunderstanding. :)

I have a checkbox, which I wish to bind to an iVar in my model ( which is a windowController).

No, you don't bind anything to an ivar, you bind things to properties.

What I am doing right now is creating an NSButton object in the model, and "assuming" .....probably incorrectly, that by having the correct getters/setters available ( eg state/setState etc) I can bind the view's checkbox title, alternateTitle, status to the NSButton in the model. That is not working for me. ("Cannot create BOOL from object <NSButton: 0x19f6c0> of class NSButton").

Your NSButton object isn't *in* the model. It may be an outlet of the window controller, but that's a feature of the controller role, not of the data model role, of the window controller. Bind *from* your view (the checkbox) *to* properties of your data model.

There's no "status" binding for a NSButton, so I assume you mean "value". You already have the "state" property to use for that.

Specifically, in IB, you'll bind the NSButton's "value" binding to the "state" property of File's Owner (your window controller).

Is this my error, or do I need to create an iVar for each of the button elements I wish to bind to?

If you want to bind the "title" and "alternateTitle" bindings too (not that I'd recommend it -- the whole point of a checkbox is that the on/ off state is shown by the checkmark, not by the text), then you must create properties of your window controller to bind to. These will be NSString* properties.

One way to do it is to create ivars backing each of the string properties and using @synthesize to create the accessors. If the title or alternate title varies over time, make sure you use the setter accessors to update the strings, so that any change gets propagated correctly to the user interface.

Another way to do it is simply to write getters for each property that returns a suitable string, without using an ivar. If the string never varies, then that's the easiest way. However, if the string varies over time, you have to take additional steps to make sure that any change gets propagated to the user interface. For example, if the string depends on another property, you can use +keyPathsForValuesAffecting<Key> (in Leopard) to register the dependency.

This issue, of ensuring correct propagation of your properties, is called "KVO-compliance", which you may have already come across.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to