如何知道哪个 NSTableView 打开了上下文菜单?

发布于 2024-09-24 18:52:32 字数 400 浏览 1 评论 0原文

我有 5 个 NSTableView 实例,它们具有相同的上下文菜单。当我收到菜单已被单击的消息时,我需要知道哪个表发送了它。我已经检查了 NSMenu 文档,但似乎没有找到一种方法来检查哪个表打开了菜单。

我正在考虑子类化 NSTableView 并在 menuForEvent 上向委托发送消息,那是最好的吗方式?

更新:

谢谢 Joshua,我正在使用 5 个表格来显示每周 5 天的任务计划。每个表代表一个工作日,我添加了用于添加和删除任务的上下文菜单。因此,当用户在工作日单击“添加任务”时,我需要知道是哪一个。我通过子类化 tableview 并在打开菜单时向委托发送消息来使其工作。通过这种方式,我的控制器知道哪个表是最后调用菜单的。 但在我看来,这并不是最好的实现,也许就像你说的问题出在用户界面上,你觉得怎么样? 何塞.

I have 5 NSTableView's instances that have the same contextual menu. When I get the message that the menu has been clicked I need to know which table sent it. I've checked the NSMenu documentation but I don't seem to find a way to check which of the tables opened the menu..

I'm thinking of subclassing NSTableView and send a message to the delegate on menuForEvent, would that be the best way?

UPDATE:

Thanks Joshua, I,am using 5 tables to display a 5 day week task planning. Each table represents a week day, and I added the contextual menu for adding and removing tasks. So when a user clicks "add task" on a week day I need to know which one. I've got it working by subclassing tableview and sending a message to the delegate when the menu is opened. In this manner my controller knows which of the tables was the last to call the menu.
But it doesn't seem to me like the best implementation to get this, maybe is like you said the problem lies on the UI, what do you think?
Jose.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-10-01 18:52:32

我看不到获取此信息的方法。菜单不“附加”到任何东西;它们显示在某个位置。你的 -menuForEvent: 覆盖可能有效,但它让我心烦意乱。

虽然这不是你问题的答案,但我承认我的第一反应是“为什么你们有多张桌子的菜单完全相同?”这对我来说更像是一个用户界面问题。人们可能会认为上下文菜单非常特定于它所代表的特定类型的事物(或其视图)。这就引出了一个问题:为什么你有 5 个表视图,它们都具有完全相同的上下文?如果所有 5 个表都表示由(大概)相同的控制器以相同方式控制的事物,那么很可能有比 5 个单独的表更好的方法来表示您的“事物集合”。

当然,我做了很多假设,但我想我的好奇心战胜了我。 :-)

I don't see a way to get this information. Menus aren't "attached" to anything; they're displayed in a location. Your -menuForEvent: override might work but it gives me the willies.

While this isn't an answer to your question, I confess my first reaction is "why do you have multiple tables with exactly the same menu?" This strikes me more as a UI issue. One would think a contextual menu would be pretty specific to the specific kind of thing (or view thereof) that it represents. That begs the question: why do you have 5 table views that all have exactly the same context? If all 5 tables represent things that are controlled in the same way by the (presumably) same controller, it's highly likely there's a better way to represent your "collection of things" than 5 separate tables.

I'm making a lot of assumptions, granted, but my curiosity is getting the best of me, I suppose. :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文