UIAlertViewから【UIAlertController】へ。

ちょっと前になりますが、UIAlertViewは非推奨になって、UIAlertControllerを使うことになったそーです。

使ってみたらdelegateとか使わないし、アラートごとに書けるし、便利でした。

一応自分用纏め。
参考サイト
Objective-C – iOS8でのダイアログ表示:廃止になるUIAlertViewと推奨されているUIAlertControllerのメリット – Qiita
UIAlertControllerでアラートやテキスト入力モーダル画面を出す。 – @niwakk7 iPhoneアプリ作っていますよ

- (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];
    
    
}

書き方は色いろあるみたい。
とりあえず使ってみるのが良いね。

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です