简体   繁体   English

我如何绑定到NSString?

[英]How do i bind to a NSString?

This question was asked before , but its not answered. 之前曾问这个问题,但没有回答。

I can bind to objects like so: 我可以绑定到这样的对象:

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

This works easy because i have a myObject.text value. 这很容易,因为我有一个myObject.text值。 But how do i bind to NSString? 但是我如何绑定到NSString?

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

You can bind to individual objects, but not temporaries. 可以绑定到单个对象,但不能绑定临时对象。 One of the reasons why we bind to key paths is to have a little more sense about the lifetime of the variable, and therefore, the binding. 我们绑定到关键路径的原因之一是对变量的生命周期以及绑定有更多的了解。 Make aString a property of the calling object, and bind to self with aString as the key path: 使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