有什么方法可以判断当前是否有UIAlertView
实例显示?因为可以在同一窗口级别显示多个 UIAlertView
。
if ([self isAlertViewShowing]) {
// do not show UIAlertView again.
} else {
// show your UIAlertView.
}
希望有这样一个方法叫做isAlertViewShowing
或者别的什么。
最佳答案
方法1- 初始化警报的默认标志...如果警报未打开,则将 isAlertViewShowing 设置为 NO
Bool isAlertViewShowing;
isAlertViewShowing = NO;
if (isAlertViewShowing == NO){
UIAlertView *alert =[[UIAlertView alloc]initWithTitle:@"Title" message:@"Message" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
// Now set isAlertViewShowing to YES
isAlertViewShowing = YES;
}
else
{
//Do something
}
方法2-
制作您自己的函数来检查是否显示任何 UIAlertView
- (BOOL)isAlertViewShowing{
for (UIWindow* window in [UIApplication sharedApplication].windows) {
NSArray* subviews = window.subviews;
if ([subviews count] > 0){
for (id view in subviews) {
if ([view isKindOfClass:[UIAlertView class]]) {
return YES;
}
}
}
}
return NO;
}
I recommended to use second method if number of
UIAlertView
instance may be more than one.
关于ios - 如何检测 UIAlertView 当前是否正在显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28791327/