简体   繁体   中英

What is the difference between NSTextField and NSTextFieldCell and to which do I bind?

More generally, what is the difference between control classes and control cell classes? Buttons have the same hierarchy, for example - NSButton and NSButtonCell.

Looking at the documentation for NSTextField bindings and NSTextFieldCell bindings , they both have the same documentation for "value". Why do they both have a value? Can one exist without the other and still display a value?

An NSString or NSNumber that is displayed as the content of the NSTextField.

An NSString or NSNumber that is displayed as the content of the NSTextFieldCell.

So when I drag a text field or any other control into my UI, how do I determine which of the objects in the hierarchy to actually bind to?

There are much more complex controls in IB that create complex hierarchies in the document outline and as much as I've searched I haven't been able to find docs that explain which objects I should focus on and work with in terms of bindings and connections.

I'll settle for an answer to NSTextField/NSTextFieldCell but would really like to know how to discern the differences between all the things that make up a control and which I should focus on when developing my app.

Bind to the NSTextField. NSCells exist to help with drawing things on screen but are largely a relic of the past when giving everything its own view was considered a performance problem. Apple is gradually deprecating them. They expose a lot of the same interface but the NSTextfield will correctly delegate the right information to its cell if needed. You really only need to be changing the cell if you plan to override its appearance.

  1. Use NSTextField to change the color of text, to set the default text string, to set the background of the field.
  2. Use NSTextFieldCell to set the default place holder text.

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