我有一个定制的NSViewController,它有两个NSTableViews并排,类似于一个拆分视图设置,在这个设置中,左tableView上的选择更改了右tableView的列表。在这种情况下,我不知道如何处理NSMenuItem事件。例如,如果我按下“删除”按钮,如何区分在按下“删除”按钮时是左表视图还是右表视图?我得到的只有delete:选择器,它是以NSMenuItem作为发送方调用的。
发布于 2014-02-18 20:14:25
首先是一些背景:
在Cocoa术语中,“活动”视图或控件称为“第一个响应者”。例如,当您在文本字段中输入文本时,文本字段被认为是“第一个响应者”,因为它是第一个响应键盘输入的对象。NSTableView还可以接收第一个响应状态(您可以使用箭头键控制选定的行)。
你可以向窗口询问它的第一个响应者,如下所示:
// it's not necessarily a sure thing that the first responder is a TableView.
id myFirstResponder = [_parentWindow firstResponder];
if (myFirstResponder == _leftTableView) {
// left tableview is selected
} else if (myFirstResponder == _rightTableView) {
// right tableview is selected
}https://stackoverflow.com/questions/21863857
复制相似问题