Re: Trying To Understand Bindings
Re: Trying To Understand Bindings
- Subject: Re: Trying To Understand Bindings
- From: Quincey Morris <email@hidden>
- Date: Sat, 13 Dec 2008 01:37:46 -0800
On Dec 12, 2008, at 22:19, Bridger Maxwell wrote:
I have a custom view subclass (sineWaveView) that the user interacts
with to change a property (connectedContact). I would like to bind
this to a value (selectedShortRangeContact) in a dictionary
(database) in another object (databaseClient). Simple, right?
Anyway, I establish the binding like so:
[sineWaveView bind:@"connectedContact" toObject:databaseClient
withKeyPath:@"database.selectedShortRangeContact" options:nil];
This question gets asked often enough that it should be in a FAQ
somewhere...
[NSObject bind:toObject:...] does *not* define a binding, but just
establishes an already-defined binding between objects. The binding
definition is a collection of behaviors plus an exposed binding name.
To use a custom binding, you must first define this behavior, giving
it a binding name (which is *not* a key or key-path). Then you
establish the binding using that name as a parameter to [NSObject
bind:toObject:...].
If you go ahead and use a key as the binding name, you get the one-way
limited behavior you saw, but it really should produce an error since
it's not really working as a binding.
How do you define the behavior of a binding? Well, an example is
described in:
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/HowDoBindingsWork.html
The value of bindings is their ease of use in IB. Programmatically,
defining new bindings is probably more trouble than it's worth -- you
may as well just program the observer behavior you want directly.
_______________________________________________
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