- iOS
-
2017-05-15 - 更新:2018-02-15
アラートを表示するにはUIAlertControllerを利用します。
アラート(ダイアログ)を表示する
タイトルとメッセージを設定し、アラートのオブジェクトを作成します。
let aTitle = "タイトル" let aMessage = "メッセージ表示" let alert = UIAlertController(title: aTitle, message: aMessage, preferredStyle: .alert)
OKボタンを作成します。
alert.addAction(
UIAlertAction(title: "OK", style: .default, handler: { action in
print("OKをタップした場合の処理")
})
)
キャンセルボタンを作成します。
処理は何もしないので、handlerはnilで大丈夫です。
alert.addAction(UIAlertAction(title: "キャンセル", style: .cancel, handler: nil))
アラートを表示する
self.present(alert, animated: false, completion: nil)






