Field editor in view-based table

  • Dear list members,

    I have an NSTextField in a row view of a view-based tableview and I see the following behavior:

    1)  to get the field editor to show I have to single click the text field and wait about 1s.
    2) The field editor only shows if I click on a part of the text field where this is text already, but if I click to the right of the current text (but still within the text field) nothing happens.
    3) Double-clicking directly in the textfield does nothing.
    4) If the row is not selected, and I single click in the textfield, the row is selected, but the field editor is not shown

    Is this all expected behaviour? I've tried googling but don't find much discussion on view-based tableviews apart from the examples from Apple. Is there some magic I can do to make the textfield subviews respond (show a field editor) more promptly?

    It makes the UI very unresponsive.

    Hoping for insight,

    Martin
  • On Fri, Apr 12, 2013, at 10:58 PM, Martin Hewitson wrote:
    > Dear list members,
    >
    > I have an NSTextField in a row view of a view-based tableview and I see
    > the following behavior:
    >
    > 1)  to get the field editor to show I have to single click the text field
    > and wait about 1s.

    Do you have a double-click action specified for the table view? If so,
    NSTableView needs to wait to determine whether to send the click to the
    hit view.

    > 2) The field editor only shows if I click on a part of the text field
    > where this is text already, but if I click to the right of the current
    > text (but still within the text field) nothing happens.

    Are your text view's constraints/autoresizing mask set up correctly to
    stretch with the cell view?

    > 3) Double-clicking directly in the textfield does nothing.

    This might be related to the aforementioned double-click behavior.

    > 4) If the row is not selected, and I single click in the textfield, the
    > row is selected, but the field editor is not shown

    This is standard behavior for table views.

    --Kyle Sluder
  • Kyle,

    >> 1)  to get the field editor to show I have to single click the text field
    >> and wait about 1s.
    >
    > Do you have a double-click action specified for the table view? If so,
    > NSTableView needs to wait to determine whether to send the click to the
    > hit view.

    Nope.

    >
    >> 2) The field editor only shows if I click on a part of the text field
    >> where this is text already, but if I click to the right of the current
    >> text (but still within the text field) nothing happens.
    >
    > Are your text view's constraints/autoresizing mask set up correctly to
    > stretch with the cell view?

    I'm still using the old struts method and I think this is all set up correctly.

    >
    >> 3) Double-clicking directly in the textfield does nothing.
    >
    > This might be related to the aforementioned double-click behavior.
    >
    >> 4) If the row is not selected, and I single click in the textfield, the
    >> row is selected, but the field editor is not shown
    >
    > This is standard behavior for table views.

    In the end I solved this by subclassing the table view, then override mouseDown and hit test the text fields to see if one was clicked on. The result works really well, though it does require/assume knowledge of the view hierarchy, which I don't like so much. But for a fixed internal UI element, it's fine.

    The code snippet is below in case it helps anyone else with this problem.

    Cheers,

    Martin

    // we need to override this to restore sensible behaviour of clicking on text fields.
    - (void)mouseDown:(NSEvent *)theEvent
    {
      [super mouseDown:theEvent];

      // Get the row on which the user clicked
      NSPoint localPoint = [self convertPoint:theEvent.locationInWindow fromView:nil];
      NSInteger row = [self rowAtPoint:localPoint];

      // If the user didn't click on a row, we're done
      if (row < 0) {
        return;
      }

      // Get the view clicked on
      NSTableCellView *view = [self viewAtColumn:0 row:row makeIfNecessary:NO];

      // get container view, which should be the only subview
      view = [view subviews][0];

      if (view) {
        // get subview at this location
        NSPoint point = [view convertPoint:[theEvent locationInWindow] fromView:nil];
        NSView *v = [view hitTest:point];
        if ([v isKindOfClass:[NSTextField class]]) {
          NSTextField *tf = (NSTextField*)v;
          if (tf.isEditable) {
            [[view window] makeFirstResponder:tf];
          }
        }
      }
    }

    >
    > --Kyle Sluder
  • On Apr 12, 2013, at 10:58 PM, Martin Hewitson <martin.hewitson...> wrote:

    > Dear list members,
    >
    > I have an NSTextField in a row view of a view-based tableview and I see the following behavior:
    >
    > 1)  to get the field editor to show I have to single click the text field and wait about 1s.
    > 2) The field editor only shows if I click on a part of the text field where this is text already, but if I click to the right of the current text (but still within the text field) nothing happens.
    > 3) Double-clicking directly in the textfield does nothing.
    > 4) If the row is not selected, and I single click in the textfield, the row is selected, but the field editor is not shown
    >
    > Is this all expected behaviour? I've tried googling but don't find much discussion on view-based tableviews apart from the examples from Apple. Is there some magic I can do to make the textfield subviews respond (show a field editor) more promptly?
    >
    > It makes the UI very unresponsive.

    Yes, this is expected, and it is the way Finder also works. Well, finder's double click action is set to open the file/app.

    corbin
previous month april 2013 next month
MTWTFSS
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          
Go to today