我正在尝试在iOS中实现OTP系统。在对OTP(一次性密码)进行getiing之后,我正在尝试更改键盘的光标,但是在键入两次键盘后光标正在移动。对于第一个文本字段它工作正常,但在尝试添加第二个文本字段时,它不起作用,直到我按键盘上的任何字符。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if(textField==_txtOtpOne)
{
if(textField.text.length==1)
{
[_txtOtpTwo becomeFirstResponder];
}
}
else if(textField==_txtOtpTwo)
{
if(textField.text.length==1)
{
[_txtOtpThree becomeFirstResponder];
}
}
else if(textField==_txtOtpThree)
{
if(textField.text.length==1)
{
[_txtOtpFour becomeFirstResponder];
}
}
else if(textField==_txtOtpFour)
{
if(textField.text.length==1)
{
}
}
return YES;
}
请帮帮我。提前致谢。
最后,我捕获发送到UITextField控件的字符,如下所示:
// Add a "textFieldDidChange" notification method to the text field control.
[textField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
它对我有用