in my application I h开发者_如何学运维ave a NSObjectController bound to all controls on the user interface. This works fine so far. The only problem I have is binding the selection of an NSComboBox to the same ObjectController. As far as I found out today the value of a ComboBox is always a string so the field in the Class of the OBjectController is also an NSString.Sounds easy for me but doesn't work.
I always get an "... class is not key value coding-compliant for the key ..."
The items in the ComboBox itself come from an other Controller, a NSArrayController. But that part works fine. All the items from the Array are items in the ComboBox. The Problem I have is getting the selection into to ObjectController.
It's just saying that whatever data-model object that NSObjectController is using does't have an appropriate key method for that value.
From looking at the Cocoa Bindings Reference documentation, the value
binding should be set to a key in your NSObjectController that corresponds to a key-value-coding compliant key in its model.
Example:
NSObjectController
mode is Class
, Class Name is foo
. Then you bind foo's key of comboSelection
to the NSComboBox's value
. What the exception is saying is that the Foo class doesn't have a method called comboSelection
:
- (NSString*)comboSelection;
- (void)setComboSelection:(NSString*)inSelection;
In the case of using a NSMutableDictionary as the NSObjectController's class, it's much easier, since the dictionary can hold arbitrary keys.
If you're using CoreData (mode = Entity), then your CoreData entity must contain the appropriate property.
精彩评论