2013-10-27 28 views

回答

1

通过子类化实现NSTableView的鼠标放下事件。在它内部检查点击的点是一行还是空白区域。如果它是空白区域,则再次选择您的表格视图的先前选定的行。

- (void)mouseDown:(NSEvent *)theEvent 
{ 
NSPoint globalLocation = [theEvent locationInWindow]; 
NSPoint localLocation = [self convertPoint:globalLocation fromView:nil]; 
NSInteger clickedRow = [self rowAtPoint:localLocation]; 

NSIndexSet* selectedRows = [self selectedRowIndexes]; 
NSLog(@"%ld",clickedRow); 
[super mouseDown:theEvent]; 

if(clickedRow == -1) 
{ 
    [self selectRowIndexes:selectedRows byExtendingSelection:NO]; 
} 

} 
+0

感谢,像魅力一样工作,确实改进了它的一点点 –

1

改进版NEHA的回答(此服从选择/取消选择)

子类NSTableView的贯彻:

- (void)mouseDown:(NSEvent *)theEvent { 

    NSPoint globalLocation = [theEvent locationInWindow]; 
    NSPoint localLocation = [self convertPoint:globalLocation fromView:nil]; 
    NSInteger clickedRow = [self rowAtPoint:localLocation]; 

    if(clickedRow != -1) { 
     [super mouseDown:theEvent]; 
    } 
} 

我们忽略的情况下,当我们不” t连续打...

+0

太棒了,+1的改进:) – Neha

相关问题