On Dec 12, 2008, at 04:36, Aaron Wallis wrote:

I'm having issues setting up bindings via code (rather than in IB)

I've got a NSObject subclass which is being used as the controller, and a NSView subclass which has a few controls like NSSliders.
In the NSObject I have the following code:

- (void)setupSliders {
[controlsView.tempSlider addObserver:self forKeyPath:@"value" options:NSKeyValueObservingOptionNew context:NULL];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject: (id)object change:(NSDictionary *)change context:(void *)context {
   NSLog(@"It's Changed!!");
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}

When I build and run the controls are rendered as expected however when I interact I don't get the "It's changed" message.

Any ideas where I could be going wrong?

Adding to Kyle's response:

1. The code you've shown us *isn't* setting up a binding, it's setting up an observer. Bindings use KVO, but the two are not the same thing.

2. The reason it doesn't work is that controls (in general) have no property named "value" -- that's the name of the binding, which is something else.

3. Theoretically, if you just wanted to observe the value of a slider, you would use one of its properties (e.g. "floatValue", "intValue", "integerValue", etc). That'll work if the property is updated KVO- compliantly -- which it may or may not be. Normally, though, you wouldn't do that. Normally, you'd bind the slider to something in your data model, and observe *that*.


_______________________________________________

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