gpt4 book ai didi

cocoa - NSTableCellView 中的多个 NSTextField;只有第一个可以直接编辑

转载 作者:行者123 更新时间:2023-12-03 17:11:42 25 4
gpt4 key购买 nike

我的 NSTableCellView 中有多个 NSTextField: enter image description here

通过双击操作,我调用 [self.outlineView editColumn:0 row:clickedRow withEvent:nil select: YES]; ,它可以激活第一个文本字段中的编辑。我还在 IB 中设置了 nextKeyViews,以便用户可以按 Tab 键来浏览所有字段。但是当我尝试直接用鼠标按键选择文本字段时,它永远不起作用。它仅选择/取消选择 NSTableCellView 上的编辑,因此每次仅编辑第一个文本字段。

我怎样才能让它工作,以便我可以选择和编辑正确的字段?

最佳答案

找到解决方案:

  • 子类 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];
}

完整引用:Respond to mouse events in text field in view-based table view

关于cocoa - NSTableCellView 中的多个 NSTextField;只有第一个可以直接编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23025014/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com