1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Datepickerが下に表示されるのを解消する

Posted at

こんにちわ。

今回は自分が困った事象に対しての
参考記事がなかったため記載します。

目次
-UITableViewのdelegateメソッドとは
-1.実際に直面した場面
-2.処理方法
-3.処理後の画面

Datepickerとは

・ユーザーが日付や時刻を選択するためのUI要素
・設定によっては日付や時刻など様々な表示が可能

1.実際に直面した場面

今回は時刻のみのDatepickerを使用しました。
ビルドすると下図のような状態に。。。。(赤枠)
スクリーンショット 2023-11-09 19.18.18.png

◯試した内容
①時刻テキストの連打、連打、連打っ!タタタタタタタタ
②再ビルド
③シュミレーター内アプリ削除→再ビルド
④Xcode削除→シュミレーター内アプリ削除→再ビルド

ちょっと真面目に考えて・・・
⑤ビルド→I/O→KeyBoard→Toggle Software KeyBoard
   ※通常のキーボードに有効
⑥ビルド→⌘ + シフト + K
   ※通常のキーボードに有効

どれも全てダメでした。。。
まあ①〜④に関してはテキトーですが笑

2.処理方法

原因はtextFieldDidBeginEditingメソッド
(textFieldがタップされ、編集が始まった時に呼ばれるUItextFieldのdelegateメソッド)
に設定漏れしていたため表示がおかしくなってました。

下記にて外観のスタイル処理を追加した。

◯全文

func textFieldDidBeginEditing(_ textField: UITextField) {
    //UIDatePickerの型を持つdatePickerViewを生成
    let datePickerView:UIDatePicker = UIDatePicker()
    //datepickerのモードを時間モードに設定
    datePickerView.datePickerMode = UIDatePicker.Mode.time
    //datepickerの外観のスタイルをホイールにする
    datePickerView.preferredDatePickerStyle = .wheels
    //テキストをdatepicker用の入力スタイルへ変更
    textField.inputView = datePickerView
            
    }

◯追加部分のみ

//datepickerの外観のスタイルをホイールにする
    datePickerView.preferredDatePickerStyle = .wheels

3.処理後の画面

処理後の画面が下図です。
スクリーンショット 2023-11-09 19.36.06.png

おぉ!と声が出てしまった。
まあこ、こんなの朝飯ま、前やけどね!!!!!

1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?