0

If I subclass NSTokenField or NSTextField and override becomeFirstResponder (for the purpose of executing some code when the control becomes first responder), when the field becomes first responder (as indicated by the focus ring, and by logging) the cursor doesn't appear.

-(BOOL)becomeFirstResponder {
    // call other code here
    NSLog(@"%@",[self.superview.window firstResponder]);
    return YES;
}

Since the default implementation of this method returns YES, why does overriding it like this cause the control to not display the cursor.

rdelmar
  • 103,982
  • 12
  • 207
  • 218

1 Answers1

2

You have to call [super becomeFirstResponder]. Overriding it interrupts the call chain. Somewhere in the super is a call to a call to a call that shows the cursor for you.

Note: In the event that you call the super method, you must return its return value. So your method would look like:

- (BOOL) becomeFirstResponder {
     if (someCondition) {
         return NO;
     }
     BOOL retVal = [super becomeFirstResponder];
     // do your stuff
     return retVal;
}
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421