Search code examples
cocoafirst-respondernssearchfield

Clean way to resign first responder of NSSearchField when done?


In my application I have an NSSearchField that is bound to an arraycontroller which performs searches as the user types.

The problem is that the search field never resigns firstresponder-status once it receives it.

What would be the cleanest way of resigning firstresponder status when the user presses Enter or clicks outside of the search field? If possible I would prefer to do as much work as possible in Interface Builder.


Solution

  • [searchField.window makeFirstResponder:nil]

    If you just want to get rid of the focus ring, you can disable it in the NIB.

    If you want to resign first responder when the user clicks empty space in the window, you have to use a custom NSView as the window's content view and override mouseDown: to call the above method.