- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试一些 MacOS 编程,但在理解绑定(bind)如何与 NSPopupButton 一起工作时遇到了一些困难。我对绑定(bind)到 NSDictionaryController 很感兴趣(我认为我不需要中间的 NSArrayController,但如果这是最好的方法,我愿意接受)。
我创建了一个 Controller 对象,它有一个属性“db”,它有一个属性“species”,它是一个 NSMutableDictionary。 'species' 字典具有用于键的 ID 和用于值的 Species 对象。物种对象具有描述属性。在 InterfaceBuilder 中,我创建了 MyController、NSDictionaryController 和一个 NSPopupButton。我想用 Species.descriptions 填充弹出窗口。选择后,我需要访问相应的ID。
我已经设置 NSDictionaryController 以将“内容字典”绑定(bind)到模型键路径“db.species”的 MyController。使用 NSPopupButton,到目前为止,我已将“内容值”绑定(bind)到 NSDictionaryController, Controller 键为“arrangedObjects”,模型键路径设置为“value.description”。
这似乎可以填充列表。我的主要问题是连接选择的最佳方式是什么。理想情况下,我想将选择连接到 NSDictionaryController,以便我可以使用 NSDictionaryController 访问选择。这样做的原因之一是我可以将其他控件连接到 NSDictionaryController 以查看当前选择。如果不是,我应该连接到 MyController 中的属性还是什么?只是在寻找最佳实践。我非常希望通过 Interface Builder 机制,以便我可以轻松地在具有不同 View 的另一个应用程序中重用模型和 Controller 设计。
以 Brian 的回答为指导进行更新:
NSPopupButton:将内容绑定(bind)到 NSDictionaryController->arrangedObjects->value.description
将内容对象绑定(bind)到 NSDictionaryController->arrangedObjects->key
将选定索引绑定(bind)到 NSDictionaryController->selectionIndex
绑定(bind) NSDictionaryController->db.species
似乎一切正常。我可以使用 [[[controller selectedObjects] lastObject] value] 从 Controller 中获取对象。我相信,它位于一组具有键值对的选定对象中。
最佳答案
我从未使用 NSDictionaryController 尝试过此操作,但我认为您可能希望将弹出窗口的 contentObjects 绑定(bind)到字典 Controller 的“arrangedObjects.key”,并将 selectedObject 绑定(bind)到字典 Controller 的“selection”键。 contentObjects 绑定(bind)会将 ID 指定为每个菜单项表示的基础对象。然后,当从弹出窗口中选择一个项目时,selectedObject 绑定(bind)会将与该菜单项对应的 ID 设置为 dict Controller 的选择。
关于objective-c - 将 NSPopupButton 绑定(bind)到 NSDictionaryController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/679207/
我一定错过了一些简单的东西,但是我在将 tableView 绑定(bind)到 NSDictionaryController 时遇到了一些麻烦。这是我当前方案的模型: TableViewColumn
我有一个 plist 文件,其中包含我需要在组织为字典字典的应用程序中显示的信息。我刚刚开始对 Cocoa 进行编程,所以不确定最好的方法。显然,我可以手动完成这一切,并对循环进行编码并将数据添加到
我有一个带有 NSDictionaryController 的基于 View 的表,其内容绑定(bind)到 Interface Builder 中的 NSUserDefaultsController
我正在尝试一些 MacOS 编程,但在理解绑定(bind)如何与 NSPopupButton 一起工作时遇到了一些困难。我对绑定(bind)到 NSDictionaryController 很感兴趣(
我是一名优秀的程序员,十分优秀!