【问题标题】:Auto shift keyboard curser for OTP in objective C目标 C 中 OTP 的自动移动键盘光标
【发布时间】:2019-08-09 21:59:50
【问题描述】:

我正在尝试在 iOS 中实现 OTP 系统。获得 OTP(一次性密码)后,我试图更改键盘的光标,但在键入两次键盘后光标正在移动。对于第一个文本字段,它工作正常,但在尝试添加第二个文本字段时,它无法正常工作,直到我按下键盘上的任何字符。

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

请帮帮我。提前致谢。

【问题讨论】:

  • 你为什么使用Swift标签?
  • @Magnas 做错了。你能帮帮我吗?
  • 使用 perfromSelector 调用 becomeFirstResponder,延迟为 0 并检查。
  • @ParagBafna 根据 u 修改代码后,文字开始追加,不移位
  • 在最后一个响应者上调用 resignFirstResponder,然后调用 becomeFirstResponder

标签: objective-c keyboard uitextfield uitextfielddelegate one-time-password


【解决方案1】:

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

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

它对我有用

【讨论】:

    猜你喜欢
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2016-06-16
    • 2011-03-01
    • 1970-01-01
    相关资源
    最近更新 更多