Cut/copy/paste keyboard shortcuts not working in NSPopover

孤街醉人 提交于 2021-01-28 08:03:46

问题


I have a macOS NSPopover based tray app which shows a popover with login fields (username and password).

Problem is that user is unable to copy-paste his email or password into text fields. The popover doesn't seem to allow keyboard shortcuts for some reason.

Did anyone have similar issues?

Relevant example available here: https://github.com/mixtly87/NSPopoverTest


回答1:


This isn't the easiest thing to solve and you need to do a few things to get this to work.

1 ) add a MainMenu to your MainMenu.xib file.

Even though the main menu won't display (because you're only doing a NSStatusBar item), you want that main menu because of the command keys in the Edit menu (i.e. something to intercept the cmd-X, cmd-C & cmd-V's). Those command keys will be sent to your text field or your webview, whatever is the first responder.

More info can be seen here.

2 )

I made your textfield the first responder by adding:

- (void)viewDidAppear
{
    [super viewDidAppear];
    [self.textField becomeFirstResponder];
}

to your ViewController.m file.

3 )

You also need to make the window brought up by the Status Item a key window. In your example app, you did have a commented out canBecomeKeyWindow method. I uncommented it out and always return TRUE.

More info can be seen here.

Hope this helps!



来源:https://stackoverflow.com/questions/49637675/cut-copy-paste-keyboard-shortcuts-not-working-in-nspopover

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