0

With a custom NSTableView, I configured IB to allow editing of the cells in the first column, and not in the second column (used for row selection).

For that, I implemented in MyTableView this method (v1), as proposed here in StackOverflow:

- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event
{
   return TRUE;
}

When I run the application and click in a cell in the first column, the content of the text field of the cell is selected (I can change the selection), but the cell cannot be edited and the control: textShouldBeginEditing: method of the delegate is not called if I press a key.

The text field is editable (set in IB and confirmed in the tableView:viewForTableColumn:row: method of the view controller). It's delegate is set to the view controller.

So to force editing, I modified the validateProposedFirstResponder:forEvent: method as (v2):

- (BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event
{
    NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
    NSView *theView = [self hitTest:point];
    if (event.type == NSEventTypeLeftMouseDown && [(NSTextField *)theView isEditable])
    {
        [self.window makeFirstResponder:theView];
        return YES;
    }
   return [super validateProposedFirstResponder:responder forEvent:event];
}

But no difference at runtime.

To test solutions, I created a small test application, cloning all the my code (the only difference is that in my app the view controller has its own XIB, whereas the clone app use the storyboard). And in that clone, everything works perfectly without any change from the original code (in both cases built using Xcode 11.3.1, for MacOS 10.11)!

When I set a breakpoint in my app's validateProposedFirstResponder:forEvent: method (v2) after setting the window's first responder, I theView.isEditable appears TRUE and theView.acceptsFirstResponder is TRUE also.

Any idea of something I missed?

Denis
  • 775
  • 7
  • 22
  • Could be anything. Create a [mre] and you'll find the cause of the issue. Did you try a small test app with a xib? Do you use Cocoa Bindings? – Willeke May 12 '20 at 22:03
  • Thanks. In the test app (using a xib), everything is still working as it should. In the main app, I tried to add the view controller to the storyboard, and the problem is still there. Not understandable! – Denis May 13 '20 at 17:55
  • I found the source of discrepancy: in my app, the table view belongs to a child window of the main window whereas in the test app, everything occurs in the main window. I understand that the first responder chain is altered in a child window. The question is: how make a child window behave like a main window? – Denis May 15 '20 at 17:28

0 Answers0