gpt4 book ai didi

cocoa - 在 Cocoa OSX 中以编程方式实例化 NSPopUpButtonCell

转载 作者:行者123 更新时间:2023-12-03 17:37:03 26 4
gpt4 key购买 nike

我有一个 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.

这些方法都没有成功地显示任何类型的菜单。是否有其他方法可以以编程方式弹出单元格中包含的菜单?

最佳答案

我认为您正在寻找 trackMouse:inRect:ofView:untilMouseUp: NSCell的方法

[theCell trackMouse:[NSApp currentEvent] inRect:NSZeroRect ofView:theView untilMouseUp:YES];

关于cocoa - 在 Cocoa OSX 中以编程方式实例化 NSPopUpButtonCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1925737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com