objective-cmacoscocoa

Disable or intercept keyboard navigation in NSTableView


MacOS app. I have a window with a NSTableView on it. Whenever the window is active, when a key is pressed that corresponds to the initial letter of a table item text, the table selects that item. How do I disable or intercept that behavior? I want my app to react to key presses, but in more ways than just selecting a table item.

Tried setting refusesFirstResponder on the table view and on the item template - doesn't help. Tried creating menu items in the main menu with a respective keyEquivalent - they only fire sometimes (see below), it looks like the table gets the first dibs on keyboard events.

In addition, the table view has a keyboard navigation timeout - if one presses keys in quick succession, only the first one leads to a selection change, the subsequent ones produce a click and the action of the menu item for that key fires. I don't want the timeout, or the clicks.

If this can be done without subclassing system classes (views, NSWindow) that are normally not meant to be subclassed - even better.


Solution

  • Set the NSTableView property allowsTypeSelect to NO. Or if you use Interface Builder there is a Type Select checkbox.