在我的应用程序中,我有一个使用 4 个文本字段输入 4 位密码的视图。当用户触摸第一个文本字段并输入第一个字符时,控件应自动转到第二个字符,依此类推.. 第四次验证应该发生。用户也应该当他触摸文本框时看不到光标。如何做到这一点?
问问题
239 次
2 回答
0
尝试以下:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if( [textField.text length]==0)
{
[nextText becomeFirstResponder];
}
return YES;
}
于 2012-09-04T07:35:51.987 回答
0
尝试这个
- (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];
}
}
}
于 2012-09-04T07:39:06.233 回答