gpt4 book ai didi

cocoa - 将 Cocoa NSComboBox 值绑定(bind)到对象

转载 作者:行者123 更新时间:2023-12-03 16:16:19 24 4
gpt4 key购买 nike

假设我有一个代表国家/地区的 NSObject 子类,例如

@interface CountryInfo : NSObject

@property (nonatomic, retain) NSString *countryName;

我的模型包含 CountryInfoNSMutableArray。我想将数组绑定(bind)到 NSComboBox 。组合框应显示国家/地区名称,并允许用户选择国家/地区。

所以,我像这样设置我的 .xib:

CountryArrayController (NSArrayController)

内容数组

  • 绑定(bind)到:文件所有者> 模型 key 路径:self.model.countries

NSComboBox

内容

  • 绑定(bind)到:CountryArrayController> Controller 键:arrangedObjects

内容值(value)

  • 绑定(bind)到:CountryArrayController> Controller key :arrangedObjects> 模型 key 路径:countryName

到目前为止,一切都很好。现在,如何绑定(bind)NSComboBoxValue?文档指出:

"An NSString or NSNumber that specifies the value of the NSComboBox."

这是什么意思?我注意到我可以将其绑定(bind)到模型上的 NSString,它将反射(reflect)所选的 countryName。但我想绑定(bind)到 CountyInfo 对象本身!无论是直接还是通过绑定(bind)到阵列 Controller 上的选择:如何设置?

最佳答案

我遇到了这个错误 - 使用的正确控件是 NSPopUpButton 而不是 NSComboBox

NSComboBox 有不同的行为,因为它需要支持用户直接输入文本的场景。 NSPopUpButton 设计为仅使用一组预定义的值,并且相对于“选择”绑定(bind)而言其行为与预期一致。

关于cocoa - 将 Cocoa NSComboBox 值绑定(bind)到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16592968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com