Re: Basic bindings questions
Re: Basic bindings questions
- Subject: Re: Basic bindings questions
- From: Steve Weller <email@hidden>
- Date: Tue, 12 Jul 2005 20:51:26 -0700
At 5:15 PM -0700 7/12/05, John C. Randolph wrote:
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.
Got it.
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:
It works now, thanks to that clue.
I had these in my code *and* in the right place, but it was
Objective-C that tripped me up. Instead of
[self willChangeValueForKey:@"sliderValue"];
sliderValue = newvalue;
[self didChangeValueForKey:@"sliderValue" ];
I had
willChangeValueForKey:@"sliderValue";
sliderValue = newvalue;
didChangeValueForKey:@"sliderValue";
I'm amazed that it passed syntax.
--
How much art could an artichoke choke if an artichoke could choke art?
_______________________________________________
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