Re: Basic bindings questions
Re: Basic bindings questions
- Subject: Re: Basic bindings questions
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 12 Jul 2005 17:15:39 -0700
On Jul 12, 2005, at 12:07 PM, Steve Weller wrote:
I have a simple test application that I am using to explore
bindings. I've done the currency converter tutorials, so I know
enough to be reckless.
I have an NSTextField and an NSSlider on a window. I created an
NSObjectController and hooked it up to my class (Clicker). I use an
instance variable bound to the text field and the slider called
sliderValue.
Questions:
1. The tutorial uses triggerChangeNotificationsForDependentKey: to
trigger a change notification, but I have found that I do not need
that. When I drag the slider and let it go, the text field changes
as expected. If I enable the slider to continuously send actions,
that works too. Why do I not need the
triggerChangeNotificationsForDependentKey?
You don't need it, because you don't have a dependent key. ;-)
You've got both controls bound to the same key.
What triggerChangeNotificationsForDependentKey: is for, is when
changing one value alters another as well. Suppose, for example,
that in your model you have a value for "radius", and a value for
"circumference". If you alter "radius", then you would want any
controls that are displaying the value for "circumference" to be
updated, so you would want to set up the dependent notifications in
that case.
2. I added a NSButton to the window and added a method clicked:
that doubles the value of sliderValue. I bound the button to the
Object controller with selection.clicked and sure enough my clicked
method is called and sliderValue is doubled each time I click it.
However the text field does not change when the button is clicked.
How do I get the text field to update when sliderValue is changed
programatically?
see -willChangeValueForKey: and -didChangeValueForKey:
-jcr
John C. Randolph <email@hidden> (408) 914-0013
Roaming Cocoa Engineer,
Available for your projects at great Expense and Inconvenience.
_______________________________________________
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