0

I am using tag field as a flag for text fields text view fields for auto-jumping to the next field:

- (BOOL)findNextEntryFieldAsResponder:(UIControl *)field {
  BOOL retVal = NO;
  for (UIView* aView in mEntryFields) {
    if (aView.tag == (field.tag + 1)) {
      [aView becomeFirstResponder];
      retVal = YES;
      break;
    }
 }
 return retVal;
}

It works fine in terms of auto-jumping to the next field when Next key is pressed. However, my case is that the keyboards are different some fields. For example, one fields is numeric & punctuation, and the next one is default (alphabetic keys). For the numeric & punctuation keyboard is OK, but the next field will stay as the same layout. It requires user to press 123 to go back ABC keyboard.

I am not sure if there is any way to reset the keyboard for a field as its keyboard defined in xib? Not sure if there is any APIs available? I guess I have to do something is the following delegate?

-(void)textFieldDidBegingEditing:(UITextField*) textField {
  // reset to the keyboard to request specific keyboard view?
  ....
}

OK. I found a solution close to my case by slatvik:

-(void) textFieldDidBeginEditing:(UITextField*) textField {
  textField.keyboardType = UIKeybardTypeAlphabet;
}

However, in the case of the previous text fields is numeric, the keyboard stays numeric when auto-jumped to the next field. Is there any way to set keyboard to alphabet mode?

Community
  • 1
  • 1
David.Chu.ca
  • 37,408
  • 63
  • 148
  • 190

1 Answers1

0

Finally I find out a way to solve my issue. In my case, I like to use Entry or Next key to auto-jump to the next available field. If the two fields in sequence have totally different keyboards, the keyboard change should be fine. However, if the one is keyboard with numeric mode, and the next one is in alphabet mode, then the auto-jump would not cause the same keyboard to change mode.

The main reason is that my call to findNextEntryFieldAsResponder: method is done in textFieldShouldReturn: delegate method. The call caused the next field becomes the responder:

 ...
 [aView becomeFirstResponder]; // cause the next fields textFieldDidBeginEditing: event
 ...

I found this in my NSLog debug message:

 textFieldShouldReturn: start
   findNextEntryFieldAsResponder
   textFieldDidBeginEditing: start
   ...
   textFieldDidBeginEditing: end
   ...
 textFieldShouldReturn: end

What I need to do is to the next field as responder out of textFieldShouldReturn: event call. I tried to use iphone's local Notification framework to fire a async-notification event within the textFieldShouldReturn: and it does what I expect.

Here is my updated codes:

- (BOOL)findNextEntryFieldAsResponder:(UIControl *)field {
  BOOL retVal = NO;
  for (UIView* aView in mEntryFields) {
    if (aView.tag == (field.tag + 1)) {
      if ([self.specialInputs containsObject:[NSNumber numberWithInt:aView.tag]]) {
        NSNotification* notification = [NSNotification notificationWithName:
            @"myNotification" object:aView];
        [[NSNotificationQueue defaultQueue]
           enqueueNotification:notification postingStyle:NSPostWhenIdle
           coaslesceMask:NSNotificationCoalescingOnName forModes:nil];
        [[NSNotifiationCenter defaultCenter] addObserver:self
           selector:@selector(keyboardShowNofication:)
           name:@"myNotification" object:nil];
      }
      else {
        [aView becomeFirstResponder];
      }
      retVal = YES;
      break;
    }
  }
  return retVal;
}
...
// Notification event arrives!
-(void) keyboardShowNofication:(NSNotification*) notification {
  UIResponder* responder = [notification object];
  if (responder) {
     [responder becomeFirstResponder]; // now the next field is responder
  }
}
...
-(void) dealloc {
  ...
  // remember to remove all the notifications from the center!
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  ...
}

where specialInputs is a NSArray of int values. It is a property can be set with a list tags as special inputs. Actually, I think all the inputs can be treated as specialInputs and it does work as well(just more notifications).

I have a complete description of codes in my blog.

David.Chu.ca
  • 37,408
  • 63
  • 148
  • 190