【问题标题】:SwiftUI TextField suggest OTP code without textContentTypeSwiftUI TextField 建议不带 textContentType 的 OTP 代码
【发布时间】:2020-10-13 08:59:26
【问题描述】:

在我的 SwiftUI 项目中使用 TextField 视图时出现了一个奇怪的行为。

使用以下代码,TextField textContentType 设置为nil(或.none,或UITextContentType.init(rawValue: "")),但键盘会提示我一个OTP 代码(例如,如果最近收到的话在之前的视图中)。为什么?

我尝试了其他有效的 textContentType,例如 .name.address、...但没有成功(只有 textContentType .password.newPassword 禁用 OTP 建议)。

struct TestView: View {
    @State private var text: String = ""
    
    var body: some View {
        TextField("", text: $text)
            .keyboardType(.numberPad)
            .textContentType(nil) // or .none, or UITextContentType.init(rawValue: "")
    }
}

对于 UIKit 项目,UITextField 可以按预期工作(没有键盘建议)。有什么想法吗?

谢谢

【问题讨论】:

    标签: textfield ios13 one-time-password swiftui


    【解决方案1】:

    显然这是 UIKit 的遗留错误。 同样的问题。

    感谢 .password 的提示

    遗憾的是,这带来了填写密码的建议

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 1970-01-01
      相关资源
      最近更新 更多