4
votes

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?

1
I have added this question after figuring out how to do it, to help others just in case they deal with the same problem.Pavel Lobodinský
In InterfaceBuilder, click on 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.Pavel Lobodinský
What good is a search field that can't become first responder?Ken Thomases
It is good in case you want to reach it only through a keyboard shortcut. I.e. prevent TAB key to get into that field. An example is Finder - you cannot get into Search field by pressing TAB key.Pavel Lobodinský
For that you want to manage the window's key view loop. If the search field can't become first responder, then it won't accept focus at all, by any means. The user won't be able to type into it.Ken Thomases

1 Answers

0
votes

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.