0

I want an NSTextField that prevents empty strings so I subclassed the NSTextField and implemented this method

-(void) textDidEndEditing:(NSNotification *)aNotification
{
  if([[self stringValue] isEqualToString:@""])
  {
    NSBeep();
   [[self window] makeFirstResponder:self];
  }
  else
  {
    //what goes here
  }
}

This works when my new text field is the second control in the window but not the first. In those cases I can't tab out of the Subclassed textfield even when its text is non-empty

So, how do I undo the makeFirstResponder method? Or is there a way of making the new textfield the current responder

Thanks in advance

stupot.

KlimczakM
  • 12,576
  • 11
  • 64
  • 83
stupot
  • 13
  • 3

1 Answers1

0

As you're overriding the base function, you should only need to make a call back to the super to make normal behaviour continue.

-(void) textDidEndEditing:(NSNotification *)aNotification
{
  if([[self stringValue] isEqualToString:@""])
  {
    NSBeep();
   [[self window] makeFirstResponder:self];
  }
  else
  {
    //what goes here - this:
    [super textDidEndEditing:aNotification];
  }
}
JamesDill
  • 1,857
  • 1
  • 18
  • 22