我有一个NSTableView放置在NSView的顶部。我想在NSView上单击鼠标指针时取消选择NSTableView。如何实现这一目标?取消选择NSTableView时,点击表格外的某处
1
A
回答
6
我知道这是旧的,但一个选项是继承NSTableView的并覆盖其鼠标按下:
- (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];
}
}
斯威夫特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)
}
}
你是什么意思“之上”?您通常不应该在视图层次结构中将其中一个视图置于其同一个视图之上;你应该只在其他视图中放置视图*。换句话说,两个兄弟姐妹的观点不应该重叠;你应该让其中一个为子视图。 – 2010-08-17 10:07:15
那是正确的。一个是另一个的子视图。但是,如何实现删除表的功能? – Subrat 2010-08-18 04:07:37
你是什么意思的“取消选择表视图”?撤消其第一响应者状态,或取消选择其中的任何选定行? – 2010-08-18 04:51:12