How to make NSTextfield lose focus when pressing Enter?

I want to create a text box in which if I exit it or press the enter key, it will lose focus. As the focus of the ring disappears. I have seen such situations, but I do not know where to place the code for this. Can someone show me how to make NSTextfield lose focus?

+4
source share
1 answer

One way would be to implement NSTextFieldDelegate, assign a delegate to the text field and call the selector (the method in your code that modifies is the first responder = nil). The delegate will be called with a message when the text field is completed with input. Check out the API here for more info:

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

+1
source

Source: https://habr.com/ru/post/1534546/


All Articles