title: Setting TextField Focus on text removal
body: <p>i have four textfields. User is allowed to enter only one digit in each text field.Once the user Enters single digit its focus should be on the next textfield. i have done this part and its working fine. Now, What i want is when i remove the text from the text field then its focus should move to previous textfield. i mean if i am deleting the text(digit) from the fourth text field then its focus should move to third text field. In short on removal of text the focus should be on previous textfield.</p>
  
  <p>Now, what my problem is when i remove the text from the textfield then its focus moves to previous textfield but it clears the text of that textfield(the textfield on which i have set the focus).What i want is the text should not be removed on focus.</p>
  
  <pre><code>in .h file
  
  IBOutlet UITextField *txtPinDigit1;
      IBOutlet UITextField *txtPinDigit2;
      IBOutlet UITextField *txtPinDigit3;
      IBOutlet UITextField *txtPinDigit4;
       UITextField *currentTextField;
  
  in .m file
  
  - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  {
      if(textField.tag==0)
      {
          currentTextField=txtPinDigit1;
      }
      else if(textField.tag==1)
      {
          currentTextField=txtPinDigit2;
      }
      else if(textField.tag==2)
      {
          currentTextField=txtPinDigit3;
          if(isDelete)
          {
              textField.text=digit3;
          }
      }
      else if(textField.tag==3)
      {
          currentTextField=txtPinDigit4;
      }
  
      return YES;
  }
  
  
  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
  {
  
      if(([textField.text length]==1)&amp;&amp;(![string isEqualToString:@""]))
      {
          if(currentTextField==txtPinDigit1)
          {
              [txtPinDigit2 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit2)
          {
              [txtPinDigit3 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit3)
          {
              [txtPinDigit4 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit4)
          {
              textField.text = [textField.text substringToIndex:MAXLENGTH-1];
              //[txtPinDigit4 resignFirstResponder];
              //[txtPinDigit1 becomeFirstResponder];
          }
      }
      else if([string isEqualToString:@""])
      {
          isDelete=YES;
          NSLog(@"replacementString:%@",string);
         // textField.text=string;
          if(currentTextField==txtPinDigit4)
          {
              textField.text=string;
              digit3=nil;
              [digit3 release];
              digit3=[[NSString alloc] initWithFormat:@"%i",[txtPinDigit3.text intValue]];
  
              [txtPinDigit3 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit3)
          {
              textField.text=string;
              [txtPinDigit2 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit2)
          {
              textField.text=string;
              [txtPinDigit1 becomeFirstResponder];
          }
          else if(currentTextField==txtPinDigit1)
          {
              textField.text=string;
             // [txtPinDigit1 resignFirstResponder];
              //[txtPinDigit1 becomeFirstResponder];
          }
      }
  
      return YES;
  }
  </code></pre>
  
  <p>in the above code MAXLENGTH=1 defined.</p>
  
  <p>any help will be appreciated.
  thanks in advance.</p>