Search code examples
objective-ccocoanstoolbar

Cocoa: How to prevent NSSearchField in a toolbar to get first responder?


When having a NSSearchField in a toolbar, it automatically becomes first responder when pressing TAB key in the window. How can I prevent that? I.e. to get the search field to refuse first responder?


Solution

  • If using Xcode 4.3.2, open up the XIB file, click the toolbar item twice to select the NSSearchField (one click selects NSToolbarItem). In the Attributes inspector, tick the "Refuses First Responder" checkbox and Bob's your uncle.

    The trick here is that NSToolbarItem cannot refuse the first responder in general. However, the NSSearchField (whose ancestor is the NSToolbarItem) can refuse.