Search code examples
cocoamacosnstextfield

Forcing a Cocoa text field to end editing


I have a view based gui that contains a text field for each gui item. When I select another menu item I want my text fields to exit out of editing mode. I could not find anyway to do this in the nsTextField docs. Any ideas?


Solution

  • You need to tell the window to remove first responder status from the control:

    [[textField window] makeFirstResponder:nil];
    

    This will end editing and remove focus from the text field.