Confused about bindings
Confused about bindings
- Subject: Confused about bindings
- From: David Aames <email@hidden>
- Date: Sun, 19 Nov 2006 12:16:17 +0000
Hello all,
I've been trying to get into bindings recently but to be honest the
more I read the docs the more confused I get. As far as I can
understand a "binding" means that the object which is bound (the one
which is sent the bind:... msg) will observe the property in the
bound-to object and will also change the property in the bound-to
object if it's property bound property changes. So let's suppose I
have two objects which inherit from NSObject and they only implement
a pair of setter/getter for a "name" property. Now I would like to
bind one of these objects to the other one (the docs that the
controller layer isn't necessary and that we can bind views to
models) imaging that one of these objects is a view and the other one
is the model. So I call:
[obj1 bind:@"name" toObject:obj2 withKeyPath:@"name" options:nil];
Is that supposed to sync the name property in the objects everytime
one of them changes? Okay... Then I call [obj2 setName:@"test
name"]; but the property of obj1 doesn't change. Another thing is
also bugging me:
1. A call changes a property in a bound object
2. The bound object changes the property in the bound-to object
3. The bound-to object issues a notification (because the bound
object observes the property) that it's property changed
4. The bound object fetches the new value using KVC and updates itself
And because it updates itself it registers that it's value has
changed to goes through the steps again. I also can't seem to figure
out the actual job of the controller in the bindings situation (it
just seems that it doesn't do anything apart from forwarding
messages). I'm also thinking whether the view bypasses the controller
when using KVC - eg when setting the "selection.property" for
example, would that translate to [[controller selection]
setProperty:...]? And my last question is whether we have to
implement fake KVO notifications when implementing our own
controllers (i.e. when a property changes in the model and we have to
issue a "whatever.changedProperty" notification)?
Obviously I'm very confused about the whole bindings things and lots
of people are talking how great it is etc so this is making me feel
really stupid asking all these questions on the list... but I want to
actually understand how bindings work and not just connect stuff in
IB. Thanks.
Kind regards,
David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden