4

現在の UIView に UIAlertView が表示されているかどうかを判断することは可能ですか (UIAlertView が作成されるたびに変数を設定する以外に)。

私はその線に沿って何かを考えています

    if ([self.view.subviews containsObject:UIAlertView]) { ... }

しかし、それは明らかにうまくいきません。

4

3 に答える 3

16

これは iOS7 以降では機能しません。

[alertView Show]は、メイン ウィンドウにサブビューを追加します。

for (UIWindow* window in [UIApplication sharedApplication].windows){
    for (UIView *subView in [window subviews]){
        if ([subView isKindOfClass:[UIAlertView class]]) {
            NSLog(@"has AlertView");
        }else {
            NSLog(@"No AlertView");
        }
    }
}

于 2012-05-24T05:42:07.937 に答える
10

私はそれがうまくいくと思います:

-(BOOL) doesAlertViewExist 
{
    if ([[UIApplication sharedApplication].keyWindow isMemberOfClass:[UIWindow class]])
    {
        return NO;//AlertView does not exist on current window
    }
    return YES;//AlertView exist on current window
}
于 2014-01-16T22:52:07.583 に答える
1

UIAlertView を表示しているビュー コントローラーのプロパティとして保存し、コードを実行すると、次のようになります。

if ([self.view.subviews containsObject:self.myalertview]) { ... }

それはうまくいくはずです。

于 2012-05-23T22:37:34.567 に答える