在我的应用程序中,我有一个 NSObjectController 绑定到用户界面上的所有控件。到目前为止效果很好。我遇到的唯一问题是将 NSComboBox 的选择绑定到同一个 ObjectController。据我今天发现, ComboBox 的值始终是一个字符串,因此 OBjectController 类中的字段也是一个 NSString。听起来对我来说很容易,但不起作用。
我总是得到一个“...类与键的键值编码不兼容...”
ComboBox 本身中的项目来自另一个控制器,即 NSArrayController。但这部分工作得很好。数组中的所有项目都是组合框中的项目。我遇到的问题是将选择放入 ObjectController 中。
in my application I have 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.
发布评论
评论(1)
它只是说 NSObjectController 使用的任何数据模型对象都没有适合该值的关键方法。
通过查看 Cocoa Bindings Reference 文档,
value
绑定应该设置为 NSObjectController 中的一个键,该键对应于其模型中的键值编码兼容键。示例:
NSObjectController
模式为Class
,类名称为foo
。然后将 foo 的comboSelection
键绑定到 NSComboBox 的value
。例外情况是 Foo 类没有名为comboSelection
的方法:在使用 NSMutableDictionary 作为 NSObjectController 类的情况下,这要容易得多,因为字典可以保存任意键。
如果您使用 CoreData (mode = Entity),则您的 CoreData 实体必须包含适当的属性。
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 isClass
, Class Name isfoo
. Then you bind foo's key ofcomboSelection
to the NSComboBox'svalue
. What the exception is saying is that the Foo class doesn't have a method calledcomboSelection
: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.