找到了解决方案:
- 子类 NSTableView / NSOutlineView
- 在子类中,覆盖
- (void) mouseDown:(NSEvent *)theEvent
在鼠标下:
NSPoint selfPoint = [self convertPoint:theEvent.locationInWindow fromView:nil];
NSInteger row = [self rowAtPoint:selfPoint];
if (row>=0) [(ContactInfoTableCellViewMac *)[self viewAtColumn:0 row:row makeIfNecessary:NO]
mouseDownForTextFields:theEvent];
在 ContactInfoTableCellViewMac 中:
- (void) mouseDownForTextFields:(NSEvent *)theEvent {
if ((NSCommandKeyMask | NSShiftKeyMask) & [theEvent modifierFlags]) return;
NSPoint selfPoint = [self convertPoint:theEvent.locationInWindow fromView:nil];
for (NSView *subview in [self subviews])
if ([subview isKindOfClass:[NSTextField class]])
if (NSPointInRect(selfPoint, [subview frame]))
[[self window] makeFirstResponder:subview];
}
完整参考:在基于视图的表格视图中响应文本字段中的鼠标事件