当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Limit textfield input to 1 and hide cursor on textfield

问题描述:

In my application i have a view to enter a 4 digit passcode using 4 textfields.when user touches first textfield and enters 1st character the control should automatically go to the 2nd and so on ..after 4th the validation should happen.Also the user should not be able to see the cursor when he touches textboxes.how to do this?

网友答案:

Try following :

   - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if( [textField.text length]==0)
    {
        [nextText becomeFirstResponder];
    }

    return YES;
}
网友答案:

Try this

     - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:      (NSRange)range     replacementString:(NSString *)string
    { 

    if(theTextField == wordTextField1) {
    [wordTextField1 setText:string];
     if(string.length == 1) {
     [wordTextField2 becomeFirstResponder];
    }
     }
    else if(theTextField == wordTextField2) {
    [wordTextField2 setText:string];
    if(string.length == 1) {
    [wordTextField3 becomeFirstResponder];
     }
       }
         else if(theTextField == wordTextField3) {
       [wordTextField3 setText:string];
    if(string.length == 1) {
    [wordTextField4 becomeFirstResponder];
    }
    }
      else if(theTextField == wordTextField4) {
      [wordTextField4 setText:string];
      if(string.length == 1) {
      [wordTextField1 becomeFirstResponder];
     }
     }
    }
分享给朋友:
您可能感兴趣的文章:
随机阅读: