All NSTableViews in my project do not receive spacebar keyboard event

NSTableView does not receive spacebar keyboard event.

When I press keyUp or keyDown, the selection changes correctly, but I cannot check / uncheck the checkbox in the first column by pressing the spacebar.

Since the arrow keys are working correctly, I am assuming the events are correctly received by the NSTableView.

Also, I just tested some delegate method in my code that might get in the way:

- (void)sendEvent:(NSEvent *)event;
- (BOOL)handleEvent:(NSEvent *)event;
- (void) keyDown:(NSEvent *)event;


and commented them out, but the space still doesn't work. Thanks to


source to share

2 answers

I actually figured out the reason. It is not true that space is validating default table elements.

Works only if System Preferences> Keyboard> Keyboard Arrow Keys> All Controls is selected.



One thing to check is that the type selection function doesn't use your whitespace. I've seen this problem in the past. You can call [yourTableView setAllowsTypeSelect:NO]

to turn it off. However, for some reason in one case, the only way I was able to successfully work around this was to implement the NSTableViewDelegate method -tableView:typeSelectStringForTableColumn:row:

and return nil:

- (NSString *)tableView:(NSTableView *)tableView typeSelectStringForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
    return nil;


This will disable type selection. In my case, it was good. As explained in the documentation:

Returns nil if no row or column is searched.

Another option would be to implement -tableView:shouldTypeSelectForEvent:withCurrentSearchString:

and return NO if the event keycode is 49 (space). So the type selection remains on, it only ignores the space.

This is just one idea. This may not actually be the cause of your problem, but I have seen the same symptoms in the past and the choice of type was the cause.



All Articles