2008 06 05One way binding to NSSlider
I was trying to bind an
I already had that kind of crash with
NSSlider's value to another object. I figured it would be nice to set the slider's value in IB and have it act as default for the bound object. While binding the slider to the object (
[myObject bind:@"opacity" toObject:opacitySlider withKeyPath:@"value" options:nil];), my code kept crashing with
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSSlider 0x125040> valueForUndefinedKey:]: this class is not key value coding-compliant for the key value.'
NSSlider does not have a value key ? That's new ! It's there in IB, it shows up in its exposedBindings … Turns out only one way is supported : binding the view (slider) to the object.
[myObject bind:@"opacity" toObject:opacitySlider withKeyPath:@"value" options:nil];
[opacitySlider bind:@"value" toObject: myObject withKeyPath:@"opacity" options:nil];
[slider valueForKey:@"value"]will crash, too. I suppose all the controls act alike, that means there's no KVC way to interact with them.
2008 06 06
Any idea why it's 'faked' and just one way ? It seems like more work than just making a 'value' property KVC compliant.
2010 06 10
This page and it's comments helped me out - thanks! :)
Yes there is, you use the accessors defined in NSControl (
Binding to something requires a KVO-compliant key. Binding from something can evidently be faked (or at least renamed).