// UIAlertControllerを生成
UIAlertController *ac = [UIAlertController alertControllerWithTitle:@"test"
message:@"test message"
preferredStyle:UIAlertControllerStyleAlert];
// UIAlertController表示処理
[self presentViewController:ac animated:YES completion:^(){
// 3秒後に実行
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Viewを閉じる
[self dismissViewControllerAnimated:YES completion:nil];
});
}];
通常、OKボタンを表示させるために UIAlertActionをUIAlertControllerにaddActionするが、OKボタンの押下を待たずに自動的にUIAlertControllerを閉じるため、UIAlertActionは編集しない。
【UIAlertControllerの最新記事】