NSTextField losing focus can be caught by :
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
Question
I have an NSTextField
which I add to the view hierarchy of my custom view and set the position for when the user clicks inside that custom view.
If the text field resigns first-responder status, e.g. because the user has clicked inside another NSTextField
in the window, I need to fetch its value and remove it from the view hierarchy again.
How can my custom view get notified of the NSTextField
it owns resigning first-responder status without having to subclass this text field just for this single purpose?
The NSTextFieldDelegate
method control:textShouldEndEditing:
won't do because it only gets called when the user actually edited something in the text field. I also need to hide the text field if the user didn't make any edits in it.
Solution
NSTextField losing focus can be caught by :
- (void)controlTextDidEndEditing:(NSNotification *)aNotification
OTHER TIPS
One more delegate method is there which will do the same thing:-
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
{
if (command==@selector(insertTab:) || (command==@selector(insertBacktab:)))
{
//Your Code
}
return YES;
}
Note:- It will work only for tab and backTab key