ちょっと前になりますが、UIAlertViewは非推奨になって、UIAlertControllerを使うことになったそーです。
使ってみたらdelegateとか使わないし、アラートごとに書けるし、便利でした。
一応自分用纏め。
参考サイト
Objective-C – iOS8でのダイアログ表示:廃止になるUIAlertViewと推奨されているUIAlertControllerのメリット – Qiita
UIAlertControllerでアラートやテキスト入力モーダル画面を出す。 – @niwakk7 iPhoneアプリ作っていますよ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
- (IBAction)Button:(id)sender { // コントローラを生成 UIAlertController * ac = [UIAlertController alertControllerWithTitle:@"タイトル" message:@"メッセージ" preferredStyle:UIAlertControllerStyleAlert]; // Cancel用のアクションを生成 UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { // ボタンタップ時の処理 NSLog(@"Cancel button tapped."); }]; // OK用のアクションを生成 UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { // ボタンタップ時の処理 NSLog(@"OK button tapped."); }]; // コントローラにアクションを追加 [ac addAction:cancelAction]; [ac addAction:okAction]; // アラート表示処理 [self presentViewController:ac animated:YES completion:nil]; } |
書き方は色いろあるみたい。
とりあえず使ってみるのが良いね。