I have a window containing three NSTextFields, like this:
+------------------------+
| +--------------------+ |
| | field1 (editable) | |
| +--------------------+ |
| +--------------------+ |
| | field2 (editable) | |
| +--------------------+ |
| +--------------------+ |
| | field3 (selectable)| |
| +--------------------+ |
+------------------------+
While field1 and field2 are editable, field3 is set to “selectable”, i.e. I can use the mouse to select text in it and copy from it, but I cannot edit the text.
field2 references field3 as its nextKeyView outlet, but when I press the Tab key when field2 is the first responder, field1 gets activated instead of field3.
As soon as I set field to ‘editable’ in Interface Builder, tabbing works as intended.
How can I enable tabbing into read-only NSTextFields?
It’s very easy when we know, just create a subclass of NSTextFieldCell :
Add a class in Xcode with this name “myNonEditableCellClass“
Code in
myNonEditableCellClass.h—
Code in
myNonEditableCellClass.mGo in “Interface Builder” : select the third
NSTextField, click again to select the NSTextFieldCell, changes its class tomyNonEditableCellClassin the Inspector.That’s it