Cocoa Design:如何在 NSCollectionView 中突出显示员工当前的部门?
我有这个核心数据支持的数据库,其中包含许多员工示例中的条目: 员工可以属于一个部门。一个部门有很多员工。 我有一个包含所有员工的 NSTableView (由 NSArrayController 支持)。我有一个 NSCollectionView (由设置为 Selection.possibleDepartments 的 NSArrayController 支持),它向我显示所选员工的可能部门。
*DDEmployee
name
image
-----
possibleDepartments <<------
selectedDepartment <<-- |
| |
*DDDepartment | |
name | |
----- | |
employees <--- |
possibleEmployees <<--------
我想强调该员工目前所在的部门
Simple 对吗?
我如何知道当前选择的部门是什么?我创建了一个部门类 (DDDepartment) 的类别,其中包含“-(BOOL)isThisTheSelectedDepartment”。在此函数中,我调用应用程序委托来为我提供主数组控制器。主阵列控制器为我提供了选定的员工。我询问被选中的员工这是否是他的部门。 图像很少,其隐藏属性绑定到representedObject.isThisTheSelectedDepartment 并取反。这不会更新 NSCollectionView (显然:P) 有没有办法用绑定来做到这一点?
谢谢
I have this core data backed database with entries like in the many employees example:
An employee can belong to a department. A department has many employees.
I have a NSTableView (backed by a NSArrayController) with all the employees. I have a NSCollectionView (backed by a NSArrayController set to selection.possibleDepartments) that shows me possible departments for the selected employee.
*DDEmployee
name
image
-----
possibleDepartments <<------
selectedDepartment <<-- |
| |
*DDDepartment | |
name | |
----- | |
employees <--- |
possibleEmployees <<--------
I want to highlight the department the employee is currently in
Simple right?
How do I know what the currently selected department is? I created a categorie of the department class (DDDepartment) that has "-(BOOL)isThisTheSelectedDepartment". In this function I call the app delegate to give me the main array controller. The main array controller gives me the selected employee. I ask the selected employee if this is his department.
There is little image and its hidden property is bound to representedObject.isThisTheSelectedDepartment and negated. This does not update the NSCollectionView (obviously :P)
Is there a way to do this with bindings?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想使用绑定来完成此操作,您可以将 NSObjectController 添加到您的笔尖。然后在对象控制器上使用键路径@“selectedDepartment”将其内容绑定到员工数组控制器中的选择。该对象控制器将始终包含所选员工的部门。
对于 DDDepartment 添加一个 BOOL“isSelected”属性。
创建 NSObjectController 的子类。将您在第 1 部分中创建的 NSObjectController 设置为其类的子类。现在在子类中重写 - (void)setContent:(id)content 为:
最后更改隐藏绑定以绑定到 isSelected 属性而不是 isThisTheSelectedDepartment 方法。这应该会为您处理好一切,并且每当您选择员工或更改员工的部门时,部门选择都会发生变化。
If you want to do it with bindings you can add an NSObjectController to your nib. Then on the object controller bind its content to the selection in the employee array controller with the keypath @"selectedDepartment". That object controller will always contain the department of the selected employee.
For DDDepartment add a BOOL "isSelected" property to it.
Create a subclass of NSObjectController. Set the NSObjectController you created in part 1 to have the subclass for its class. Now in the subclass override - (void)setContent:(id)content to be:
Finally change your hidden binding to bind to the isSelected property instead of your isThisTheSelectedDepartment method. This should take care of everything for you and cause the department selection to change whenever you select an employee or change the department of an employee.