NSTextView wont update unless I click on it, and it wont focus. Any ideas?

我们两清 提交于 2019-12-11 15:06:44

问题


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


回答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;
   }


来源:https://stackoverflow.com/questions/5684272/nstextview-wont-update-unless-i-click-on-it-and-it-wont-focus-any-ideas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!