paranitips

Never stop learning! がモットーのゆるふわエンジニアブログ

UIAlertViewを表示しているかどうかをチェックする

ユーザとして、ダイアログが複数回出てくるのはかなりストレスに感じます。

UIAlertViewの表示チェックを行うことで、それを回避します。

-(void)showDialog
{
  // ダイアログを表示中かチェックする
  for (UIWindow* window in [UIApplication sharedApplication].windows){
      for (UIView *subView in [window subviews]){
          if ([subView isKindOfClass:[UIAlertView class]]) {
              return;
          }
      }
  }
  
  // ダイアログを表示する
  UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"たいとる"
                                                  message:@"メッセージ"
                                                 delegate:self
                                        cancelButtonTitle:@"NO"
                                        otherButtonTitles:@"OK", nil];
  [alert show];
  [alert release];
}

参考