1
2

More than 3 years have passed since last update.

UITextFieldでキーボードのサジェストとフォーカスの動きが意図しない件について

Last updated at Posted at 2021-02-22

事の始まり

サービスの新規登録画面を作り直すことになりました。

内容としては簡単なもので、項目は以下の通り。
・メールアドレス入力
・パスワード入力
・パスワード再入力

UITextFieldをパラパラっと設置して、キーボードのタイプを指定して、

最後にパスワードは見えないようにisSecureTextEntryを忘れずに。

簡単ですね😀!!

SignUpViewController.swift
class SignUpViewController: UIViewController {
    @IBOutlet private weak var emailAddressText: UITextField!
    @IBOutlet private weak var passwordText: UITextField!
    @IBOutlet private weak var rePasswordText: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        emailAddressText.keyboardType = .emailAddress
        emailAddressText.isSecureTextEntry = false
        emailAddressText.textContentType = .emailAddress

        passwordText.keyboardType = .asciiCapable
        passwordText.isSecureTextEntry = true
        passwordText.textContentType = .password

        rePasswordText.keyboardType = .asciiCapable
        rePasswordText.isSecureTextEntry = true
        rePasswordText.textContentType = .password
    }
}

動かしてみる&問題が見つかる

まずメールアドレス入力、次にパスワード入力、最後にパスワード再入力っと。

ん???

なんでパスワード再入力時にメールアドレスユーザ名のサジェストが出てくるんだ・・・🤔

しかもサジェストを選択するとメールアドレスに入力されてフォーカスがパスワード入力に移動する😇

調査してみる

きっとtextContentTypeが間違っているんだ!

と、いうことで色々組み合わせを変えてみる。

まずは何も指定しないケース

emailAddress password rePassword
isSecureTextEntry false false false
textContentType nil nil nil

これは問題なし。サジェストは表示されず、想定通りの動き。

しかしパスワード丸見えなのでサービスとしては駄目。

次に色々と指定してみるケース

emailAddress password rePassword
isSecureTextEntry false true true
textContentType username password password
emailAddress password rePassword
isSecureTextEntry false true true
textContentType nil nil nil
emailAddress password rePassword
isSecureTextEntry false false false
textContentType username password password
emailAddress password rePassword
isSecureTextEntry false false false
textContentType username newpassword newpassword
emailAddress password rePassword
isSecureTextEntry false false false
textContentType username password password

組み合わせとしては全部駄目でした。

サジェストが出てしまいフォーカスも意図しない動きになる。

どうやらisSecureTextEntrytextContentTypeをいじるとサジェストが出てしまうようだ・・・🤔

パラメータの組み合わせで解決するかなと思ったが駄目みたい。

教えてApple!!

というわけでApple Technical Support Incidentを投げてみました。

やりとりの内容としては以下の通りです。

筆者「UITextFieldを3つ置いてtextContentTypeとisSecureTextEntryを指定します。」

筆者「特定の組み合わせで意図しないサジェストが出てしまいます。解決方法はないでしょうか?」

Apple「問題を解決するため問題箇所に特化したサンプルプロジェクトを送って下さい。」

〜サンプルプロジェクトを送る〜

Apple「フィールドのキーボードの提案、またはプロジェクトが示す動作は、システムのバグと見なされます。(Google翻訳)」

Apple「Feedback Assistantでバグレポートを送って下さい。」

とのことでした。

おわりに

とりあえずバグレポートは作成して報告したので修正を待とうと思います。

今回初めてTSI投げましたが、解答が早く不具合もすぐ認めてくれたので正直びっくりしました。

以上です。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2