Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSTextField not noticing lost focus when pressing Tab?

I can't seem to find a way to get notified when an NSTextField loses focus by pressing the Tab key. I get a nice textDidEndEditing when clicking another control or when pressing Enter, but not if I change the focus by pressing the Tab key.

Also tried to yank KeyDown and doCommandBySelector for this purpose but I got nowhere.

Any ideas?

Thanks in advance

Edit:

Forgot to mention, but I tried resignFirstResponder too. This is the code I tried:

- (BOOL)resignFirstResponder
{
    NSRunAlertPanel(@"", @"Lost Focus",@"OK", nil, nil);
    return [super resignFirstResponder];
}
- (BOOL)becomeFirstResponder
{
    NSRunAlertPanel(@"", @"Got focus",@"OK", nil, nil);
    return [super becomeFirstResponder];
}

Strangely, what happens here is that when getting focus, both becomeFirstResponder and resignFirstResponder are called one after the other. But when changing focus away from the control, neither are.

like image 770
hasvn Avatar asked Dec 01 '25 06:12

hasvn


1 Answers

"I get a nice textDidEndEditing when clicking another control or when pressing Enter, but not if I change the focus by pressing the Tab key."

As of April 2011, with OS X 10.6 libs, I'm using:

- (void)controlTextDidEndEditing:(NSNotification *)aNotification

...to listen for NSTextField losing focus, and it's working correctly. Is this possible in your situation? Is it something that used to be broken, but is now fixed by Apple?

If so, it's much less code :).

like image 126
Adam Avatar answered Dec 03 '25 16:12

Adam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!