LoginSignup
2
0

More than 3 years have passed since last update.

【Objective-C】UIAlertControllerでダイアログを表示する方法

Posted at

UIAlertControllerとは?

UIAlertControllerとは下記画像のようなダイアログを表示するためのクラスです。
今回はこのクラスを使い、Objective-Cでダイアログの実装を行う方法を紹介していきます。
スクリーンショット 2020-05-18 23.53.19.png

サンプルコード

//下記のように記述する事で、UIAlertControllerを初期化します。
//alertControllerWithTitleに指定した文字列が太文字で表示されます。
//messageに指定した文字列が小見出し的な感じで、小文字で表示されます。
 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"UIAlertControllerStyle.Alert" message:@"iOS8" preferredStyle:UIAlertControllerStyleAlert];

//下記のコードでボタンを追加します。また{}内に記述された処理がボタン押下時の処理なります。
 [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  //ボタンがタップされた際の処理
  }]];

[alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  //ボタンがタップされた際の処理
  }]];

//下記のコードでダイアログを表示します。
[self presentViewController:alertController animated:YES completion:nil];
2
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
2
0