Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make NSTextfield lose focus when Enter is pressed?

I want to make a text field in which if I click out of it, or press enter, it makes it lose focus. As in the focus ring disappears. I've have seen situations like this, but I do not know where to place the code for it. Can anyone show me how to make the NSTextfield lose it's focus?

like image 951
Jelly Avatar asked Nov 01 '22 02:11

Jelly


1 Answers

One method would be to implement the NSTextFieldDelegate, assign the delegate to your text field, and have it call a selector (a method in your code that changes makes the first responder = nil). The delegate will be called with a message when the text field is finished receiving input. Check out the API here for more information:

https://developer.apple.com/library/mac/documentation/cocoa/reference/NSTextFieldDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSTextFieldDelegate

like image 191
SeniorShizzle Avatar answered Nov 15 '22 06:11

SeniorShizzle