繁体   English   中英

我如何绑定到NSString?

[英]How do i bind to a NSString?

之前曾问这个问题,但没有回答。

我可以绑定到这样的对象:

[[aCellView textField] bind:@"stringValue"
                               toObject:myObject
                            withKeyPath:@"text"
                                options:nil]];

这很容易,因为我有一个myObject.text值。 但是我如何绑定到NSString?

[[aCellView textField] bind:@"stringValue"
                               toObject:aString
                            withKeyPath:@""  // What should the keyPath be?
                                options:nil]];

可以绑定到单个对象,但不能绑定临时对象。 我们绑定到关键路径的原因之一是对变量的生命周期以及绑定有更多的了解。 使aString成为调用对象的属性,并使用aString作为关键路径绑定到self

[[aCellView textField] bind:NSValueBinding toObject:self withKeyPath:@"aString" options:@{}];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM