4

I have a NSTextField in my window (added with IB) with a hidden title bar but when I click on it when the app is running, it does not respond or place a cursor in its field. Is there anything I am doing wrong? it is setup in the most standard way possible, an editable textfield on a window.

Thanks.

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • maybe it's set to be readonly? – Eimantas Oct 03 '11 at 11:51
  • Sorry I edited the question with a critical point that this only occurs when I set the window to have a hidden titlebar in IB – Zigglzworth Oct 03 '11 at 12:02
  • possible duplicate of [Why NSWindow without styleMask:NSTitledWindowMask can not be keyWindow?](http://stackoverflow.com/questions/4946342/why-nswindow-without-stylemasknstitledwindowmask-can-not-be-keywindow) –  Oct 04 '11 at 03:41

1 Answers1

11

Create a custom class that inherits from NSWindow, and set it as the NSWindow Object in InterfaceBuilder. Then override the following methods:

//
// canBecomeKeyWindow
//
// Overrides the default to allow a borderless window to be the key window.
//
- (BOOL)canBecomeKeyWindow
{
    return YES;
}

//
// canBecomeMainWindow
//
// Overrides the default to allow a borderless window to be the main window.
//
- (BOOL)canBecomeMainWindow
{
    return YES;
}
Bart
  • 19,692
  • 7
  • 68
  • 77
Brandon Horst
  • 1,921
  • 16
  • 26
  • +1: I assumed there was something I was overlooking - I didn't imagine it could be so complicated as to require subclassing and overriding methods like this. (Not that that's complicated, so much as it's not easy to track down/debug.) – ArtOfWarfare Jan 25 '14 at 17:05
  • 1
    Only "canBecomeKeyWindow" is needed for NSTextField to response. The window does not have to be the main window. – Yoav May 24 '16 at 07:40