Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在cocoa中检测右键和左键单击_Objective C_Macos_Cocoa_Nsview_Nswindow - Fatal编程技术网

Objective c 如何在cocoa中检测右键和左键单击

Objective c 如何在cocoa中检测右键和左键单击,objective-c,macos,cocoa,nsview,nswindow,Objective C,Macos,Cocoa,Nsview,Nswindow,我想在鼠标左键和右键上创建一个动作。单击可能是在NSTableViewCell、NSView等上(就像我们右键单击窗口时,它会弹出一个窗口)。有没有API来完成这样的任务?如果没有,请选择其他方式。 提前感谢您的帮助。您必须覆盖NSResponder方法,如: - (void) mouseDown: (NSEvent*) theEvent; - (void) rightMouseDown: (NSEvent*) theEvent; 参考文献: 更新:如下所述,NSView和NSTableVie

我想在鼠标左键和右键上创建一个动作。单击可能是在NSTableViewCell、NSView等上(就像我们右键单击窗口时,它会弹出一个窗口)。有没有API来完成这样的任务?如果没有,请选择其他方式。 提前感谢您的帮助。

您必须覆盖NSResponder方法,如:

- (void) mouseDown: (NSEvent*) theEvent;
- (void) rightMouseDown: (NSEvent*) theEvent;
参考文献:


更新:如下所述,
NSView
NSTableView
继承了NSResponder的这些方法。

NSView
NSTableView
继承了
NSResponder
NSResponder
具有
rightMouseDown
事件和其他鼠标事件

与此相关的一些文档: