简体   繁体   中英

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. But how do i bind to 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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