以编程方式创建 Cocoa PopUpMenus 并从使用界面生成器构建的 GUI 项目中获取代码

发布于 2024-08-04 21:35:44 字数 222 浏览 1 评论 0原文

我需要以编程方式创建许多 Cocoa 项目,并且我能找到的大多数资源都集中在使用构建器创建 GUI。有什么方法可以获取使用 Xcode 中的界面生成器创建的界面项的目标 C 代码吗?另外,我对 PopUpMenus 有点困惑。 PopUpMenus 是包含在 PopUpButtons 内还是独立的?另外,任何人都可以将我链接到如何使用 Cocoa 和 Objective-C 以编程方式创建 PopUpMenus 的详细描述吗?

I need to create many Cocoa items programmatically and most resources I can find focus on creating GUI with the builder. Is there any way to get the objective C code for an interface item created using the interface builder in Xcode? Also, I am a little confused about PopUpMenus. Are PopUpMenus contained inside PopUpButtons or are the independent? Also, can anyone link me to a good description of how to create PopUpMenus programmatically Using Cocoa and Objective-C?

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

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

发布评论

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

评论(1

简美 2024-08-11 21:35:44

这取决于“PopUpMenus”的含义。在 Cocoa 中,菜单就是一个菜单,特别是 NSMenu 的一个实例。 NSPopupButtons 有一个关联的 NSMenu 对象,您可以使用 -setMenu: 方法将其分配给按钮。

您当然可以使用 NSMenu 和 NSMenuItem 类以编程方式构造菜单。查看 NSMenu 文档中的各种 -addMenuItem: 方法。

如果您有对菜单的引用,特别是连接到 Interface Builder 中菜单的插座实例变量,则还可以通过编程方式访问 Interface Builder 中创建的菜单的组件。

如果您指的是单击鼠标右键时出现的上下文菜单,您所需要做的就是使用 -setMenu: 方法将菜单连接到要附加到的视图/控件。您也可以在 Interface Builder 中建立此连接。

It depends on what you mean by "PopUpMenus". In Cocoa a menu is a menu, specifically an instance of NSMenu. NSPopupButtons have an associated NSMenu object which you can assign to the button using the -setMenu: method.

You can certainly construct menus programmatically using the NSMenu and NSMenuItem classes. Take a look at the various -addMenuItem: methods in the NSMenu documentation.

You can also access the components of a menu created in Interface Builder programmatically if you have a reference to the menu, specifically an outlet instance variable that is connected to the menu in Interface Builder.

If you're referring to contextual menus that appear when you click the right mouse button, all you need to do is connect your menu to the view/control you want to attach it to with the -setMenu: method. You can make this connection in Interface Builder also.

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