I have a NSTableView place开发者_JS百科d on top of NSView. I want to deselect the NSTableView when mouse pointer is clicked on NSView. How to achieve this?
I know this is old, but one option is to subclass NSTableView and override its mouseDown:
- (void)mouseDown:(NSEvent *)event {
[super mouseDown:event];
NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
NSInteger row = [self rowAtPoint:point];
if (row == -1) { // We didn't click any row
[self deselectAll:nil];
}
}
Swift 3 version:
override open func mouseDown(with event: NSEvent) {
super.mouseDown(with: event)
let point = convert(event.locationInWindow, from: nil)
let rowIndex = row(at: point)
if rowIndex < 0 { // We didn't click any row
deselectAll(nil)
}
}
精彩评论