2

在我的应用程序中,我有一个 NSObjectController 绑定到用户界面上的所有控件。到目前为止,这工作正常。我唯一的问题是将 NSComboBox 的选择绑定到同一个 ObjectController。据我今天发现,ComboBox 的值始终是一个字符串,因此 OBjectController 类中的字段也是一个 NSString.Sounds 对我来说很容易但不起作用。

我总是得到一个“ ......类与键的键值编码不兼容......

ComboBox 本身中的项目来自另一个控制器,一个 NSArrayController。但这部分工作正常。Array 中的所有项目都是 ComboBox 中的项目。我遇到的问题是将选择放入 ObjectController。

4

1 回答 1

2

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.

于 2009-11-07T19:36:14.950 回答