1

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

我正在考虑继承 NSTableView 并在 menuForEvent 上向代表发送消息,这是最好的方法吗?

更新:

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

4

1 回答 1

1

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. :-)

于 2010-09-29T20:13:28.760 回答