1

I have multiple NSTextFields in my NSTableCellView: enter image description here

With a double-click action, I call [self.outlineView editColumn:0 row:clickedRow withEvent:nil select: YES]; which works in activating editing in the first text field. I have also setup nextKeyViews in IB so that user can press Tab key to tab through all the fields. But when I try to select the text fields directly with the mouse key press, it never works. It only selects/deselect editing on the NSTableCellView, and hence only edits the first text field each time.

How can I get this to work so that I can select and edit the correct field?

Z S
  • 7,039
  • 12
  • 53
  • 105

1 Answers1

1

Found a solution:

  • subclass NSTableView / NSOutlineView
  • in subclass, override - (void) mouseDown:(NSEvent *)theEvent

In mouseDown:

        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];

In 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];
}

Full reference: Respond to mouse events in text field in view-based table view

Community
  • 1
  • 1
Z S
  • 7,039
  • 12
  • 53
  • 105