NSComboBox与Core Data一起使用的正确绑定是什么? [英] What are the correct bindings for an NSComboBox for use with Core Data

查看:221
本文介绍了NSComboBox与Core Data一起使用的正确绑定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,如果你有一个Core Data应用程序,有两个实体(员工和部门)。员工与部门(部门)具有一对一的关系,而逆是一对多关系(员工)。在UI中,您可以选择单个员工实体,并在详细区域中编辑详细信息(当然还有其他属性,还有用于添加和编辑部门实体的UI)。使用弹出式按钮时,绑定为:

Imagine if you will a Core Data app with two entities (Employee, and Department). Employees have a to-one relationship with department (department) and the inverse is a to-many relationship (employees). In the UI you can select individual Employee entities and edit the details in a detail area (there are of course other attributes and there is UI for adding and editing Department entities). When using a popup button the bindings are:

content = PopUpArrayController.arrangedObjects

values = PopUpArrayController.arrangedObjects.name (name是NSString)

selected object = EmployeeArrayController.selection.department.name

content = PopUpArrayController.arrangedObjects
content values = PopUpArrayController.arrangedObjects.name (name is an NSString)
selected object = EmployeeArrayController.selection.department.name

这允许在弹出式菜单中查看所有部门,正确选择当前员工部门,并允许按预期更改部门。目标是为NSComboBox更改此值,以便用户可以标签到框并键入部门名称而不切换到鼠标。我已经尝试了许多不同的绑定来完成这一点。我甚至有一个运行与这些绑定工作:

This allows for viewing of all departments in the popup menu, correct selection of the current Employee's department, and allows that department to be changed as expected. The goal is to change this for an NSComboBox so that the user can tab to the box and type the department name in without switching to the mouse. I have tried numerous different bindings to accomplish this. I even had it work for one run with these bindings:

content = PopUpArrayController.arrangedObjects.name

value = EmployeeArrayController.selection.department.name

content = PopUpArrayController.arrangedObjects.name
value = EmployeeArrayController.selection.department.name

至少一次这样工作正常甚至在输入的文本与任何现有部门不匹配时添加了新部门)。现在,它将显示可用的部门并自动完成,但是当在组合框中更改值时,不会使用正确的值更新模型。如果使用弹出窗口设置或更改部门,则组合框中将显示正确的部门。

At least once this worked as expected (it even added a new department when the entered text did not match any existing department). Now however it will display the available Departments and auto complete but will not update the model with the correct value when the value is changed in the combo box. If the Department is set or changed with the popup the correct department is shown in the combo box.

有人知道我缺少什么吗?谢谢。

Does anyone know what I am missing? Thanks.

推荐答案

所以我已经找出至少一个答案这个问题。简短的版本是没有办法只使用绑定来实现这个效果。我终于在网上找到了 http://frankschmitt.org/2007/06/comboboxen 这给了我足够的细节来解决这个问题(虽然代码格式化在帖子中有一些问题,但NSValueTransformer的文档填充在洞)。

So I have figured out at least one answer to this issue. The short version is that there is not a way to just use bindings to accomplish this effect. I did finally find http://frankschmitt.org/2007/06/comboboxen on the web which gave me enough detail to solve the problem (though the code formatting in the post has some issues, but the docs for NSValueTransformer filled in the holes).

这篇关于NSComboBox与Core Data一起使用的正确绑定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆