我是这项技术的新手,我想在父节点和子节点的Right click
上显示不同的上下文菜单 ..
答案 0 :(得分:2)
子类NSOutlineView
并实施- (NSMenu *)menuForEvent:(NSEvent *)theEvent
。
-(NSMenu*)menuForEvent:(NSEvent*)evt
{
NSLog(@"menuForEvent %@ %@",self, [self delegate]);
NSPoint pt = [self convertPoint:[evt locationInWindow] fromView:nil];
int row=[self rowAtPoint:pt];
// create menu ...
return menu;
}
在Mac OS 10.5及更高版本中,在nib中创建NSMenu并设置委托并实现:
-(void)menuNeedsUpdate:(NSMenu *)menu
答案 1 :(得分:0)
快速版本:
class SubclassOutlineView: NSOutlineView {
override func menu(for event: NSEvent) -> NSMenu? {
let point = convert(event.locationInWindow, from: nil)
let row = self.row(at: point)
let item = self.item(atRow: row)
let menu = NSMenu()
// ...
return menu
}
}
我所缺少的是item(atRow:
,它为您提供了所需的数据源项。发现此相关问题:
How do you add context senstive menu to NSOutlineView (ie right click menu)