What are the correct bindings for an NSComboBox for use with Core Data

谁说胖子不能爱 提交于 2020-01-13 19:25:05

问题


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
content values = PopUpArrayController.arrangedObjects.name (name is an NSString)
selected object = EmployeeArrayController.selection.department.name

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

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.


回答1:


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).



来源:https://stackoverflow.com/questions/3003002/what-are-the-correct-bindings-for-an-nscombobox-for-use-with-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!