Question

How can I know when an NSTextField becomes the first responder (i.e. when the user click on it to activate it, but before they start typing). I tried controlTextDidBeginEditing but this doesn't get called until the user types the first character.

Was it helpful?

Solution

Subclass the NSTextField and overwrite the

- (BOOL)becomeFirstResponder

method, defined in the NSResponder class (a superclass of NSTextField), like so:

- (BOOL)becomeFirstResponder {

  BOOL flag=[super becomeFirstResponder];

  if(flag)
  {
    // text field will become first responder
  }

  return flag
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top