views:

79

answers:

1

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];

}

+2  A: 

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...

tc.
I've tried the appDelegate idea, but I still must be missing something, as I'm still getting multiple popups. I'm not sure how I'd keep track of alerts across multiple viewControllers. Thanks!
Gorgando
I got it to work by showing the alert in the appDelegate, and then using a notification to notify the appDelegate each time the UIAlertView is closed. This way the appDelegate keeps track of whether or not there is an alert with a boolean variable.
Gorgando