如何防止同时弹出多个 UIAlertView 警报?

发布于 2024-09-12 07:31:21 字数 887 浏览 7 评论 0原文

我的选项卡栏应用程序有三个选项卡,每个选项卡都有自己的导航结构。我的应用程序中的几个视图通过 Web 服务调用加载数据。这些视图注册此通知是为了了解应用程序何时变为活动状态,以便它们可以重新加载数据:

    [[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(reloadView) name:UIApplicationDidBecomeActiveNotification 
        object:NO];

当应用程序变为活动状态时,这些视图都尝试重新加载其数据;但是,如果没有 Internet 连接,则会捕获错误并向用户显示 UIAlert。问题是,如果其中 3 个视图尝试重新加载数据,则会弹出 3 条警报消息。

如何防止向用户弹出多个警报?

我感谢您的所有想法、想法和建议!

谢谢!

Brad

编辑:我尝试将其放入我的 appDelegate 中,但即使使用此方法,我似乎也会收到多个弹出窗口。

-(void)displayAlertWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Retry",nil];
[alert show];
[alert release];

}

My tabbar application has three tabs, each with its own navigational structure. Several of the views throughout my app load data via web service calls. These views register this notification in order to know when the app becomes active, so that they can reload the data:

    [[NSNotificationCenter defaultCenter] addObserver:self 
        selector:@selector(reloadView) name:UIApplicationDidBecomeActiveNotification 
        object:NO];

When the app becomes active, these views all try to reload their data; however, if there is no Internet connection, the errors are caught and a UIAlert is shown to the user. The problem is that if 3 of these views are trying to reload data, 3 alert messages pop up.

How do I prevent multiple alerts from popping up to the user?

I appreciate all your thoughts, ideas, and suggestions!!

Thanks!

Brad

Edit: I tried putting this in my appDelegate, but even using this method, I seem to get multiple popups.

-(void)displayAlertWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:delegate cancelButtonTitle:@"Cancel" otherButtonTitles:@"Retry",nil];
[alert show];
[alert release];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东走西顾 2024-09-19 07:31:21

跟踪当前是否正在显示警报(或最近已被消除)。确实没有其他办法了。

如果您将功能保留在应用程序委托中,那么您只需执行类似 [(MyAppDelegate*)[UIApplication sharedApplication].delegate displayNetworkFailureDialog] 的操作即可。

编辑:请注意,有些人可能会对在应用程序委托中粘贴随机全局内容感到不满...

Keep track of whether a alert is currently being displayed (or has been dismissed recently). There really isn't another way.

If you stick the functionality in your app delegate, then you can just do something like [(MyAppDelegate*)[UIApplication sharedApplication].delegate displayNetworkFailureDialog].

EDIT: Note that some people may frown on sticking random global cruft in your app delegate...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文