开发者

Deselecting NSTableView when clicked somewhere outside the table

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)
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜