1

I'm attempting to customize a NSTableHeaderCell to detect mouse clicks. In the past i've used things such as an NSTrackingArea or overriding the mouseDown event such as:

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

These methods don't seem to work properly on a NSTableHeaderCell as its a cell rather than a view.

Does anyone have any suggestions on detecting mouse events on a cell? Specifically I would like to catch the first click (along with its location).

Kyle
  • 17,317
  • 32
  • 140
  • 246

1 Answers1

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.

Jay
  • 6,572
  • 3
  • 37
  • 65
  • With `tableView:mouseDownInHeaderOfTableColumn:` there is no way to cancel the event is there? So if your column is sortable, this is going to cause the table to sort.... In my case, I have an icon in the header cell that I'm trying to raise an event on. I think I almost have it figured out using another method, but just to check, would there be a way to cancel the sorting when using the `tableView:mouseDownInHeaderOfTableColumn:` delegate? – Kyle Mar 12 '14 at 16:30