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

2

9

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.

Peroration answered 3/4, 2016 at 21:25 Comment(0)
S
11

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.

Shults answered 3/4, 2016 at 21:54 Comment(0)
P
0
  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.
Pellerin answered 3/4, 2016 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.