【问题标题】:Password autofill is not working in swift密码自动填充无法快速运行
【发布时间】:2020-06-17 16:49:13
【问题描述】:

有 6 个文本字段可以接受 otp(一次性密码)。但是当我得到 otp 并尝试在 UITextField 上设置密码自动填充时,只有最后 4 个填充项正在使用 otp。但不是所有领域。 我已附上屏幕截图

在这里,我已将所有 textContentType 设置为 .oneTimeCode 如何解决问题,请帮忙。

https://i.stack.imgur.com/kkIuQ.jpg

【问题讨论】:

标签: swift uitextfield


【解决方案1】:

尝试连续命名您的文本字段txt1 txt2 txt3 txt4 tt5 txt6

override func viewDidLoad() {
 super.viewDidLoad()
 txt1.becomeFirstResponder()
}

 func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        if ((textField.text?.count)! < 1 ) && (string.count > 0) {
            if textField == txt1 {
                txt2.becomeFirstResponder()

            }

            if textField == txt2 {
                txt3.becomeFirstResponder()

            }

            if textField == txt3 {
                txt4.becomeFirstResponder()
            }

            if textField == txt4 {
                txt5.becomeFirstResponder()
            }
            if textField == txt5 {
                txt6.becomeFirstResponder()
            }
            if textField == txt6{
                txt6.becomeFirstResponder()
            }

            textField.text = string
            return false
        } else if ((textField.text?.count)! >= 1) && (string.count == 0) {
            if textField == txt2 {
                txt1.becomeFirstResponder()
            }
            if textField == txt3 {
                txt2.becomeFirstResponder()

            }
            if textField == txt4 {
                txt3.becomeFirstResponder()
            }

           if textField == txt5 {
                txt4.becomeFirstResponder()
            }
            if textField == txt6 {
                txt5.becomeFirstResponder()
            }
            if textField == txt1{
               txt6.resignFirstResponder()
            }

            textField.text = ""
            return false
        } else if (textField.text?.count)! >= 1 {
            textField.text = string
            return false
        }

        return true
    }

快乐编码

【讨论】:

    【解决方案2】:

    试试这个自动填充文本字段

    txtOTP.textContentType = .oneTimeCode
    

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2019-09-02
      • 2019-04-11
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 2019-04-05
      • 2010-11-29
      相关资源
      最近更新 更多