【问题标题】:AutoFill issue on iOS for getting phone numberiOS上用于获取电话号码的自动填充问题
【发布时间】:2021-11-04 07:54:13
【问题描述】:

点击键盘时自动填充建议无法填充文本字段。这是我在代码中所做的:

textField.keyboardType = .phonePad
textField.textContentType = .telephoneNumber

但是当函数

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool

被称为它只是返回空的replacementString字符串。

设备 ios 版本 14.7

编辑: 我发现如果我不指定/委托

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool

功能一切正常。仍然很困惑为什么。

【问题讨论】:

    标签: ios swift uitextfield


    【解决方案1】:

    将内容类型设置为 otp 后尝试

    textField.textContentType = .oneTimeCode
    

    【讨论】:

    • 但是更改 textContentType 将导致自动填充建议从电话号码更改为消息一次代码,这不是我对这个特定文本字段的意图,因为我希望用户能够快进默认文本字段。
    • 苹果不提供其他形式的OTP
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2017-04-14
    • 2019-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多