Search code examples
objective-ccocoamacosdelegatesnstextfield

How to find which NSTextfield is focused


I'm having a problem finding out which NSTextfield is focused.

I am building a multi-language form and have several NSTextfields for data entry. I have to change the text input source for some of the NSTextfields during data entry, and I need it to happen automatically.

For now, I can change the text input source as I mentioned here without problem.

The problem that I have is to change the input source right when the NSTextfield becomes focused. If I use the controlTextDidBeginEditing: delegate method it changes the source input after typing the first letter. This means that I lose the first word I typed in proper language.

Is there any delegate to find it ?


Solution

  • You can subclass your NSTextField and override - (BOOL)becomeFirstResponder (NSResponder) to respond to this kind of event.

    You can also try control:textShouldBeginEditing: instead.