記録。

めも。

.actionsheetにはtextfieldを使うことができない

iosアプリ開発中にエラーが発生したので、その時に知ったことをメモ。

UIAlertControllerを使おうとしようとした時、

init(title: String?, message: String?, preferredStyle: UIAlertControllerStyle)

上記のpreferredStyleを.actionではなくて.actionsheetを使ってみたけど、
どうやらtextFieldは入れることができないらしい。

以下がそのときに発生したエラー。

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Text fields can only be added to an alert controller of style UIAlertControllerStyleAlert'


ということでUIAlertControllerにtextFieldを使うときは.actionを使いましょう。

いや、たぶん.actionと.actionsheetのそれぞれが使用される目的が違うはず。
それを自分が知っていなかったからこのようなことが起きてしまったのかも。
公式のドキュメントをじっくり読もう。

公式ドキュメント
UIAlertController - UIKit | Apple Developer Documentation