1

我正在尝试自定义 aNSTableHeaderCell以检测鼠标点击。在过去,我使用过诸如NSTrackingArea或覆盖mouseDown事件之类的东西,例如:

-(void)mouseDown:(NSEvent *)theEvent
{
    NSLog(@"Mouse down");
}

这些方法似乎不能在 a 上正常工作,NSTableHeaderCell因为它是一个单元格而不是一个视图。

有人对检测单元格上的鼠标事件有任何建议吗?具体来说,我想捕捉第一次点击(连同它的位置)。

4

1 回答 1

2

The way this is designed to be handled by AppKit is via your NSTableViewDelegate and

tableView:mouseDownInHeaderOfTableColumn:
'Tells the delegate that the mouse button was clicked in the specified table column’s header.'

Unless you have very specific needs to actually handle the mouse-down in your cell it might be easier to just implement that method in your delegate.

于 2014-03-12T16:00:26.890 回答