I have a subclassed NSView that I would like to contain an editable NSTextField, similar to Spotlight.
I am having significant difficult getting the text field to select and highlight. If I click quickly and rapidly over the editing area of the textfield, I can actually enter text, but it appears greyed out, as though I am adding text to a field of an app that is not foremost.
I have tried to get focus of the View's window using viewDidMoveToWindow
, but apparently NSMenuItem's windows are carbon windows that don't handle keys very well.
Long story short, what is a good way to go about making this work successfully? I know that Spotlight is a borderless window, but that is not suitable for my purposes.
Any and all suggestions would be very helpful.
After much research, two things are common consensus:
(1) If you find yourself looking for ways to subclass a built-in UI element for special the chances are that you're doing something wrong, or at very least, there is a better way to do what you're trying to do.
(2) The reason to follow the interface guidelines is to be more future-compatible. There is no guarantee that a sub-classed UI element will be compatible with future versions of the OS.
Brass Tacks - subclassing UI elements is generally not advised.