使用 UITextContentType 并从键盘建议中选择不会填充文本字段

问题描述

我在文本字段上设置了以下内容

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

所以它会在键盘显示电话号码的建议,但在选择建议后,它不会填充 textField。

我已经实现了 shouldChangeCharactersIn 委托方法

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

它被调用了两次,但字符串是空的。 我参考了这个答案:shouldChangeCharactersIn Combined with Suggested Text

但这不起作用,因为它在第二次调用委托时返回空字符串。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)