将 NSPopUpButton 绑定到 NSArray
我对 NSPopUpButton
上的绑定有点迷失。我有一个自定义类,其中包含我想在弹出窗口中显示的一系列项目。这些项是 NSManagedObject 的子类,它们包含在 NSArray 中。我不想使用 NSArrayController ,因为我在以编程方式更改选择时遇到了很多麻烦,而且感觉使实现变得混乱。
问题很简单,我不知道如何将数组正确绑定到弹出窗口。我所做的就是在弹出菜单上列出数组项,但标题是核心数据 URI。我相信我可以使用 description
方法来更改标题,但这听起来不太可取。
有什么想法如何正确地将 NSArray
绑定到 NSPopUpButton
吗?
I'm a little lost with bindings on NSPopUpButton
. I have a custom class that holds an array of items that I'd like to display in a pop up. These items are subclasses of NSManagedObject
s and they are contained in an NSArray
. I don't want to use an NSArrayController
since I've had lots of trouble changing the selection programmatically and it feels like cluttering the implementation.
The problem is simply that I don't know how to bind the array properly to the pop up. All I have managed to do is list the array items on the pop up menu, but the titles are core data URIs. I believe I could use the description
method to change the title, but this does not sound very advisable.
Any ideas how to bind NSArray
to the NSPopUpButton
properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我想我解决了。我只是为
NSPopUpButton
创建了这些绑定:"Content" 到
items
属性(类型为NSArray*
)“选定对象”到
selectedItem
(类型为Item*
)最后“Content Values”到
items.name
对于第三个绑定,我实现了
valueForKeyPath:
第三个绑定也可以是标题的单独数组,但我这更加灵活。
I think I solved it. I simply created these bindings for
NSPopUpButton
:"Content" to the
items
property (of typeNSArray*
)"Selected Object" to
selectedItem
(of typeItem*
)Finally "Content Values" to
items.name
For the third binding I implemented
valueForKeyPath:
The third binding could've been also a separate array for titles, but I this is much more flexible.