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?