0

I dont have time right this second to put some sample code, (Ill edit my question tomorrow and add some) but basically what happens is that I have a Window. It works fine usually, but if I use

 [myWindow setStyleMask:NSBorderlessWindowMask]

to make it borderless, the NSTextView it contains will stop gaining focus even when you click on it: the ring will never appear, the cursor wont change and the scroll bar will remain gray.

Something else that happens when I make it borderless is that it wont update! I basically have this

 [lyricsView setString:someString];

to update the string inside it. The Console marks me no errors, but the string wont appear in the Text View unless I click on it.

All of this stops happening if I remove the line setting the styleMask to Borderless. Any ideas? Suggestions? Comments? Cheers?

Thank You! Kevin

Kevin Chavez
  • 949
  • 1
  • 11
  • 27
  • 1
    I’m not sure about `-setString:`, but your first question (about gaining focus) has already been answered on Stack Overflow: http://stackoverflow.com/questions/4946342/why-nswindow-without-stylemasknstitledwindowmask-can-not-be-keywindow –  Apr 16 '11 at 03:26

1 Answers1

1

From the documentation of NSWindow:

The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise.

So subclass your window and add this line

   -(BOOL)canBecomeKeyWindow
   {
        return YES;
   }
Stefanf
  • 1,663
  • 13
  • 15
  • Indeed! I created a category to override the method just as you do here, and it worked! Not only can the window now gain focus but also the text field, and it updates normally. Thank you! – Kevin Chavez Apr 16 '11 at 14:46