Cocoa-Bindings :将 NSComboBox 选择绑定到 NSObjectController 中的字段

发布于 2024-08-09 22:16:59 字数 363 浏览 4 评论 0原文

在我的应用程序中,我有一个 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月朦胧 2024-08-16 22:16:59

它只是说 NSObjectController 使用的任何数据模型对象都没有适合该值的关键方法。

通过查看 Cocoa Bindings Reference 文档,value 绑定应该设置为 NSObjectController 中的一个键,该键对应于其模型中的键值编码兼容键。

示例:

NSObjectController模式为Class,类名称为foo。然后将 foo 的 comboSelection 键绑定到 NSComboBox 的 value。例外情况是 Foo 类没有名为 comboSelection 的方法:

- (NSString*)comboSelection;
- (void)setComboSelection:(NSString*)inSelection;

在使用 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文