使用 Cocoa OSX 以编程方式实例化没有 NSPopUpButton 的 NSPopUPMenu
不久前,我制作了一个可可小部件,它是一个按钮,按下该按钮时,会弹出一个弹出菜单并处理选择。使用 NSPopupMenuButton 类这非常简单,但现在我需要做一些稍微不同的事情。我有一个 openGL 小部件,当我单击该小部件的某个部分时,我需要弹出与从 NSPopupMenuButton 获得的相同弹出菜单,但没有按钮。我在 NSPopupMenuButton 的文档中找不到对此菜单类本身的任何引用。我想做的事情可能吗?或者我需要从头开始构建这个弹出菜单吗?
A while back I made a cocoa widget that was a button that when pressed, would pop up a popup menu and handle the selection. This was quite trivial using the NSPopupMenuButton class but now I need to do something slightly different. I have an openGL widget and when I click on a certain part of this widget, I need to pop up the same pop up menu that you get from the NSPopupMenuButton but without the button. I could not find any reference to this menu class itself inside the documentation for the NSPopupMenuButton. Is what I am trying to do possible? Or do I need to build this pop up menu from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有单独的 NSPopUpMenu。 NSPopUpButton 的菜单是一个 NSMenu。
如果您想要一个没有弹出按钮的弹出菜单,则需要使用 NSPopUpButtonCell 来显示菜单。当然,这是假设您有充分的理由在 OpenGL 视图中伪造弹出按钮,而不是简单地使用标准 NSPopUpButton。
There is no separate NSPopUpMenu. The menu of an NSPopUpButton is an NSMenu.
If you want a pop-up menu without a pop-up button, you'll need to use NSPopUpButtonCell to display the menu. Of course, this is assuming you have a good reason to fake a pop-up button in an OpenGL view, instead of simply using the standard NSPopUpButton.