假设我有一个NSObject代表一个国家的子类,例如
@interface CountryInfo : NSObject
@property (nonatomic, retain) NSString *countryName;
我的模型包含一个NSMutableArrayof CountryInfos。我想将数组绑定到NSComboBox. 组合框应显示国家名称,并允许用户选择国家。
所以,我像这样设置我的 .xib:
CountryArrayController (NSArrayController)
内容数组
- 绑定到:文件所有者> 模型密钥路径:self.model.countries
 
NSC组合框
内容
- 绑定到:CountryArrayController > Controller Key:arrangeObjects
 
内容价值
- 绑定到:CountryArrayController > Controller Key:arrangeObjects > Model Key Path:countryName
 
到现在为止还挺好。现在,如何绑定NSComboBox? 该文档指出:
"An NSString or NSNumber that specifies the value of the NSComboBox."
这是什么意思?我注意到我可以将它绑定到NSString我的模型上,它会反映选定的countryName. 但我想绑定到CountyInfo对象本身!无论是直接,还是通过绑定到我的阵列控制器上的选择:我该如何设置?