检查是否显示UIAlertView [英] Check if a UIAlertView is showing
问题描述
我有一个发布HTTP数据并在出现错误时显示UIAlertView的方法.如果我有多个HTTP帖子,那么对于每个错误,我都会显示多个UIAlertView.
I have a method that posts HTTP data and displays a UIAlertView if there is an error. If I have multiple HTTP post I will show multiple UIAlertView for every error.
我只想在不显示其他UIAlertView的情况下显示UIAlertView. 我该如何确定?
I want to show a UIAlertView only if is not showing other UIAlertView. How can I determine this?
推荐答案
在调用的对象上,在调用UIAlertView上的show方法之前,设置一个ivar.
On the object that calls set an ivar before invoking the show method on your UIAlertView.
...
if (!self.alertShowing) {
theAlert = [[UIAlertView alloc] initWithTitle:title message:details delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
self.alertShowing = YES;
[theAlert show];
}
...
然后在警报的委托方法中,将标志ivar设置为no:
Then in your delegate method for the alert manage setting your flag ivar to no:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
...
self.alertShowing = NO;
}
如果您希望警报按顺序显示,我会发布通知以将每条消息添加到队列中,然后仅在解除警报后将消息从队列中移出.
If you want the alerts to show sequentially, I would post notifications to add each message to a queue and then only take a message off the queue after an alert is dismissed.
这篇关于检查是否显示UIAlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!