views:

51

answers:

2

I have a subclassed NSTextField to limit the maximum length (only 1 character). Now, once the user finishes entering this one character I would like to move the focus to the next NSSTextView. This is where I need some help. How can I tell the application "move the focus to the next field"? I suppose I need to call the parent view from the subclassed NSTextField, something like:

[[self parent] nextKeyView];

But how do I do this?

+3  A: 

How about [[self window] makeFirstResponder:[self nextKeyView]]?

Dave DeLong
Careful when / why you call this, though - if you call it any time the field's contents change, "delete" will move to the next field too. Very frustrating. :)
Joshua Nozzi
Thanks Dave, this does the trick!
Cimm
And thanks Jushua for the useful note. :)
Cimm
A: 

You don't need to subclass NSTextField for this, just implement the text delegate method -textDidChange:

NSResponder