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.

Était-ce utile?

La 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
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top