How to remove focus from an NSTextField

Sometimes you need to make your text field give up first responder status, and therefore end editing. You’d think that – looking at the NSControl Class Reference – we should call something along the lines of validateEditing or abortEditing. But that doesn’t work.

Instead, we can set our text field’s window to “no first responder”. This approach works with any NSControl element:

This approach is similar to telling a UITextField to resignFirstResponder (the old “invisible button to dismiss the iOS keyboard” ploy).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.