开发者

NSTableView and NSSearchField in an NSView, which is the outlet of an NSMenuItem, don't work

开发者 https://www.devze.com 2022-12-23 08:03 出处:网络
I\'m having an NSView, which is set as the view: outlet of an NSMenuItem. The view contains an NSTableView (inside an NSScrollView) and an NSSearchField. The NSMenu is shown when the user clicks a spe

I'm having an NSView, which is set as the view: outlet of an NSMenuItem. The view contains an NSTableView (inside an NSScrollView) and an NSSearchField. The NSMenu is shown when the user clicks a specific NSStatusItem. When I launch the application from Xcod开发者_高级运维e (Build and Run), the controls behave well, but whenever I launch it from the Finder (like the users would), they don't work and don't take any focus. My application is an LSUIElement. Can anyone help me out? Thanks.


Since, your application is an UIElement, it's NSMenu won't take focus. You must set an NSTimer to 0.01 seconds to show the NSMenu, and you should make the application active:

- (void)statusItemClicked {
    [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(showMenu) userInfo:nil repeats:NO];
    [NSApp activateIgnoringOtherApps:YES];
}
- (void)showMenu {
    [statusItem popUpStatusItemMenu:statusMenu];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消