无法从文档控制器填充 NSMenu

发布于 2024-08-17 12:54:36 字数 231 浏览 4 评论 0原文

我有一个 MainMenu.xib 和一个 MyDocument.xib。我需要从文档控制器动态填充一些 NSMenuItem,但我不知道如何从 MainMenu.xib 访问它。

我尝试将 NSObject 添加到 MainMenu.xib 并使其成为我的文档控制器的实例,但我无法从控制器上的 NSArrayController 填充 NSMenuItem。

我应该在代码中执行此操作还是有其他方法来解决此问题?

I've a MainMenu.xib and a MyDocument.xib. I need to dynamically populate some NSMenuItem's from my document controller but I'm at a loss on how to get to it from MainMenu.xib.

I've tried adding an NSObject to MainMenu.xib and make it an instance of my document controller but I can't populate the NSMenuItem's from the NSArrayController I have on the controller.

Should I just do this in code or is there another way of tackling this?

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

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

发布评论

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

评论(1

追风人 2024-08-24 12:54:36

在 MyDocument.m 中:

- (void)windowControllerDidLoadNib:(NSWindowController *) aController

尝试以下操作:

NSMenu * mainMenu = [[NSApplication sharedApplication] mainMenu];

请参阅 Apple 文档中的应用程序菜单和弹出列表简介了解更多信息

In MyDocument.m:

- (void)windowControllerDidLoadNib:(NSWindowController *) aController

try this:

NSMenu * mainMenu = [[NSApplication sharedApplication] mainMenu];

See Introduction to Application Menus and Pop-up Lists in Apple docs for more

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