この場合のUIAlertControllerの表示方法。
// コントローラを生成
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"Info"
message:@"Message"
preferredStyle:UIAlertControllerStyleAlert];
// アクションを生成
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
// ボタンタップ時の処理
}
];
// コントローラにアクションを追加
[ac addAction:okAction];
// アクションシート表示処理
[self.window.rootViewController presentViewController:ac animated:YES completion:nil];
ViewController で presentViewControllerで表示するときは、
[self presentViewController:ac animated:YES completion:nil];と記述するのが一般的だが、AppDelageteの中で表示する場合は、
[self.window.rootViewController presentViewController:ac animated:YES completion:nil];と記述する。
参考記事:
http://stackoverflow.com/questions/13430179/appdelegate-rootviewcontroller-and-presentviewcontroller
【UIAlertControllerの最新記事】