我有一個openGL GUI界面,我需要一個彈出式菜單,當我的openGL顯示中按下某個按鈕時,會彈出一個菜單。我想顯示一個菜單,類似於按下NSPopUPButton時彈出的菜單,但我不能使用Cocoa按鈕本身。看來最好的方法是使用NSPopupButtonCell。我不能在這裏發佈我的代碼,因爲我在Lisp中編寫代碼並通過客觀的C橋訪問Cocoa,但我只想看看下面的pseduo代碼是否應該顯示菜單,或者如果我的明顯缺陷邏輯:在可可OSX中編程實例化一個NSPopUpButtonCell
• 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.
這些方法都無法成功顯示任何種類的菜單。有沒有其他的方式來編程彈出單元格中包含的菜單?
這樣做伎倆謝謝。 – Mike2012 2009-12-18 20:24:42