我在NSView上放置了一个NSTableView。我想在NSView上单击鼠标指针时取消选择NSTableView。怎么做到这一点?
答案 0 :(得分:6)
我知道这是旧的,但是一个选项是子类NSTableView并覆盖它的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版本:
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)
}
}