Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextField resigning first responder

I'm trying to have my text field resign first responder when the user is done editing it, like when they hit enter. The delegate method is getting called but what I have now doesn't work, what is the proper way to go about doing this?

- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
    [fieldEditor resignFirstResponder];
    return YES;
}
like image 478
avizzini Avatar asked Nov 28 '22 18:11

avizzini


1 Answers

From the docs on the -resignFirstResponder method:

Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.

This code should do it:

[myWindow makeFirstResponder:nil];
like image 177
Joshua Nozzi Avatar answered Dec 16 '22 00:12

Joshua Nozzi