这个问题被问了before ,但没有得到答复。
我可以像这样绑定(bind)到对象:
[[aCellView textField] bind:@"stringValue"
toObject:myObject
withKeyPath:@"text"
options:nil]];
这很容易,因为我有一个 myObject.text
值。
但是我如何绑定(bind)到 NSString 呢?
[[aCellView textField] bind:@"stringValue"
toObject:aString
withKeyPath:@"" // What should the keyPath be?
options:nil]];
最佳答案
您可以绑定(bind)到单个对象,但不能绑定(bind)到临时对象。我们绑定(bind)到关键路径的原因之一是对变量的生命周期以及绑定(bind)有更多的了解。将 aString
设为调用对象的属性,并以 aString
作为关键路径绑定(bind)到 self
:
[[aCellView textField] bind:NSValueBinding toObject:self withKeyPath:@"aString" options:@{}];
关于objective-c - 如何绑定(bind)到 NSString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17819863/