【问题标题】:How to bind selection of table to an instance variable?如何将表的选择绑定到实例变量?
【发布时间】:2012-07-13 13:56:54
【问题描述】:
我将一个表绑定到一个名为 Persons 的 ArrayController。如果我在窗口上添加一个 textField 并将其绑定到 Controller Key: selectionIndex,则 textField 将显示我选择的项目的索引。
问题是:我想将选择的索引绑定到 MyAppDelegate 类的实例变量,而不是绑定到 textField,我该怎么做?
【问题讨论】:
标签:
objective-c
xcode
cocoa
【解决方案1】:
您可以将selectionIndexes 绑定到具有NSIndexSet* 对象值的@property 或一对显式方法,例如- (NSIndexSet*) myIndex; 和- (void) setMyIndex:(NSIndexSet*) aSet;(在这种情况下,selectionIndexes 绑定到self.myIndex) . NSIndexSet 类有一个 firstIndex 便捷方法,在只有一个选定值的情况下返回(可能只有)整数值。