在目标C中自动切换OTP的键盘光标

问题描述 投票:1回答:1

我正在尝试在iOS中实现OTP系统。在对OTP(一次性密码)进行getiing之后,我正在尝试更改键盘的光标,但是在键入两次键盘后光标正在移动。对于第一个文本字段它工作正常,但在尝试添加第二个文本字段时,它不起作用,直到我按键盘上的任何字符。 enter image description here

 - (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;
}

请帮帮我。提前致谢。

objective-c keyboard uitextfield uitextfielddelegate one-time-password
1个回答
0
投票

最后,我捕获发送到UITextField控件的字符,如下所示:

  // Add a "textFieldDidChange" notification method to the text field control.
[textField addTarget:self 
              action:@selector(textFieldDidChange:) 
    forControlEvents:UIControlEventEditingChanged];

它对我有用

© www.soinside.com 2019 - 2024. All rights reserved.