Programaticallyスをインスタンス化しNSPopUpButtonCellアOSX
-
20-09-2019 - |
質問
私はopenGLバージョンとしてポップアップメニューのときに呼び出されるこの特定のボタンを押すと私のopenGL表示されます。新しいメニューと同様のポップアップしますを押すと、NSPopUPButtonが利用できなくなりました。は、ココアボタンそのものです。この最良の方法そのために利用されNSPopupButtonCell.できないので後の私のコードでこちらを皆様にお伝えしたくて書き込みのコードをLispとアクセス用のココアを通じて客観的なC橋が確かめたかったですし以下の場合pseduoコードが感じられるように表示する必要のあるメニューの場合ことは明白であると同時に彼は私の論理:
• 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.
これらの方法で成功したく何らかのメニューが表示されます。ある他の方法でprogramticallyポップアップメニューに含まれるすることは可能です。
解決
と思いを探して trackMouse:inRect:ofView:untilMouseUp:
方法 NSCell
[theCell trackMouse:[NSApp currentEvent] inRect:NSZeroRect ofView:theView untilMouseUp:YES];
他のヒント
私はあなたが、プレーンNSMenu
を使用して+[NSMenu popUpContextMenu:withEvent:forView:]
を呼び出したほうが良いと思います。あなたが唯一の10.6以降をターゲットしている場合、あなたはまた、あなたのメニューの位置を超えるもう少しコントロールを与える、-[NSMenu popUpMenuPositioningItem:atLocation:inView:]
をチェックアウトすることがあります。ただ、メニューを構築(またはnibファイルからロード)、あなたのビューでmouseDown:
を実装し、それを表示し、NSMenu
がそこからすべての詳細の世話をする必要があります。ただ、項目が選択されたときにアクションメソッドが正しく呼び出されるように、各NSMenuItem
のターゲットとアクションが設定されていることを確認します。