是否可以将 NSTextfield
仅绑定(bind)到 NSArray 或 NSSet/关系中的一个特定条目。
我可以看到使用filterPredicate
的Control Key
绑定(bind)到NSArrayController
的可能性,但是Model Key是什么路径
?
此外,单个 NSArrayController 可以有多个 filterPredicates 方法或属性。
最佳答案
据我所知,您无法绑定(bind)到集合中的特定对象,因为无法一致地表达集合中的给定对象。从集合中提取对象的唯一方法是anyObject
。对于数组来说则是另一回事。可以对它们进行索引,并且绑定(bind) API 允许您执行此操作:
// Edit: changed the code to use bindings directly instead of KVO
[_textFild bind:NSValueBinding
toObject:array[indexToBindTo]
withKeyPath:@"firstName"
options:nil];
您无法直接在 Interface Builder 中执行此操作,因此必须在代码中完成。
关于objective-c - 是否可以将 `NSTextfield` 仅绑定(bind)到 NSArray 或 NSSet/Relationship 中的一个特定条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17127809/