Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 846
Matt Avatar asked Apr 03 '16 21:04

Matt


1 Answers

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.

like image 167
Aaron Avatar answered Nov 03 '22 02:11

Aaron