Why not store all your references in an array (a little lookup table), then set the firstResponder to the reference from the index of the object in the array + 1 and roll over to index 0 if the index is past the count of the array?
Shouldn't it be [self makeFirstResponder:myTextFieldRef]? On Aug 2, 2015, at 10:13 PM, Ken Thomases wrote: > On Aug 2, 2015, at 7:29 PM, Graham Cox <graham....@bigpond.com> wrote: > >> I have a series of NSTextFields and I want to automatically move the >> keyboard focus to the ‘next’ field when the one preceding it has a certain >> number of characters entered. My code is: >> >> - (void) controlTextDidChange:(NSNotification*) obj >> { >> NSTextField* control = [obj object]; >> >> NSString* text = [control stringValue]; >> >> if([text length] >= 4 ) >> { >> NSString* shortStr = [[text substringToIndex:4] >> uppercaseString]; >> [control setStringValue:shortStr]; >> >> NSResponder* nextField = [control nextKeyView]; >> >> NSLog(@"got 4 characters: '%@', moving to field: %@", shortStr, >> nextField ); >> >> [[self window] makeFirstResponder:nextField]; >> } >> } > > You can try [[self window] selectKeyViewFollowingView:control] instead. > > If that doesn't work, you can try [control.currentEditor > tryToPerform:@selector(insertTab:) with:self]. > > >> … the code does what it should, detecting the string length and calling >> -makeFirstResponder when it gets a length of 4 or more … >> >> The current field does lose focus, but the next field never gains it, so the >> flow of text entry from field to field doesn’t occur as it should. Also, >> even though the first field is set as the window’s initialFirstResponder, >> and does get the keyboard focus ring, the actual field editor isn’t ready >> and typing just produces a beep - the user has to click in the field to make >> it accept text. These probems may well be related. > > Are you certain the window is key? Does your app do anything unusual with > activationPolicy or activation, generally? > > Regards, > Ken > > > _______________________________________________ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com > > This email sent to z...@mac.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com