我有一个 openGL GUI 界面,我需要一个弹出菜单,当在我的 openGL 显示中按下某个按钮时将调用该菜单。我想显示一个类似于按下 NSPopUPButton 时弹出的菜单,但我不能使用 Cocoa 按钮本身。似乎最好的方法是使用 NSPopupButtonCell。我不能在这里发布我的代码,因为我正在用 Lisp 编写代码并通过一个 Objective-C 桥访问 Cocoa,但我只是想看看下面的伪代码是否应该显示菜单,或者是否存在明显的缺陷我的逻辑:
• Pseudo Code for function that is called when button is pressed:
• Initialize an NSPopUpButtonCell Using initTextCell: "test" pullsDown: NO
• allocate an NSMenu using alloc
• add two menu items using addItem:
• set the menu of the popUpButtonCell to be the menu that was just allocated using setMenu:
• Next I tried two methods to try and get the menu to actually be displayed,
first I tried using drawWithFrame:inView: and when that did not work I also tried
using drawBezelWithFrame:inView: eventhough the docs said not to use but I just
tried it out of desperation.
• finally, when the draw methods did not work I tried using performClick: on the
popupButtonCell to try and simulate the click.
这些方法都没有成功地显示任何类型的菜单。是否有其他方法可以以编程方式弹出单元格中包含的菜单?