NSView 中的 NSTableView 和 NSSearchField(NSMenuItem 的出口)不起作用

发布于 2024-08-26 02:51:47 字数 362 浏览 1 评论 0原文

我有一个 NSView,它被设置为 NSMenuItemview: 出口。该视图包含一个 NSTableView (在 NSScrollView 内)和一个 NSSearchField。当用户单击特定的 NSStatusItem 时,会显示 NSMenu。当我从 Xcode(构建和运行)启动应用程序时,控件表现良好,但每当我从 Finder 启动它时(就像用户那样),它们就不起作用,也不会获得任何焦点。我的应用程序是一个LSUIElement。有人可以帮我吗?谢谢。

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 Xcode (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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言 2024-09-02 02:51:47

由于您的应用程序是一个 UIElement,因此它的 NSMenu 不会获得焦点。您必须将 NSTimer 设置为 0.01 秒才能显示 NSMenu,并且您应该使应用程序处于活动状态:

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

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文