1

I am trying to implement an OTP system in iOS. After getiing OTP (One Time Password) I am trying to change the cursor of keyboard but the cursor is shifting after typing in keyboard twice. For the first textfield it is working fine but while trying to add in the second textfield it is not working until I press any charecter from keyboard.
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;
}

Please help me out. Thanks in advance.

Mahboob Nur
  • 739
  • 2
  • 9
  • 34

1 Answers1

0

Finally , I catch the characters sent to a UITextField control like this:

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

And it worked for me

Mahboob Nur
  • 739
  • 2
  • 9
  • 34