Reputation: 439
In my ViewController.m I have declared
@interface ViewController ()
{
//...
UIAlertView * alertView;
//...
}
The alertview is created here:
- (void)iCloudTeavitused {
//...
//If the alertview happens to be previously open, it will be dismissed (I use a corresponding flag to indicate this)
[alertView dismissWithClickedButtonIndex:alertView.cancelButtonIndex
animated:YES];
//...
alertView = [[UIAlertView alloc] initWithTitle:AMLocalizedString(@"iCloud is available", @"iCloud is available")
message:AMLocalizedString(@"This app stores", @"This app automatically stores your settings in the cloud to keep them up-to-date across all your devices")
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:AMLocalizedString(@"OK_iCloudYES", @"OK"), nil];
[alertView show];
//...
}
I localize words by calling
LocalizationSetLanguage(@"en");
The localization takes place in Localization.m where I it also does:
ViewController* viewController = [[ViewController alloc]init];
[viewController iCloudTeavitused];
Thus, on some occasions, iCloudTeavitused gets called from ViewController.m also. The problem is that when it needs to dismiss the alert view (if one happens to be open) by calling
[alertView dismissWithClickedButtonIndex:alertView.cancelButtonIndex
animated:YES];
in iCloudTeavitused, this method actually doesn't get called (while, for example, creating another alertView
DOES get called).
My guess is that dismissing the old alertView
isn't fired because I'm calling this through Localization.m.
Am I right and what am I doing wrong in my code?
Upvotes: 0
Views: 211
Reputation: 38162
I think the issue here could be that you are dealing with multiple instances of ViewController. If you create and display an alert view using one instance of ViewController and then try to dismiss it through another one, it won't work. You should either save the instance of UIAlertView on some singleton object or your app delegate and refer that object to dismiss it before presenting the new one Or you can use browse through all the subviews in the window and dismiss a UIAlertView (if any).
for (id aSubview in [iView valueForKey:@"subviews"]) {
if ([aSubview isKindOfClass:[UIAlertView class]]) {
[(UIAlertView *)aSubview dismissWithClickedButtonIndex:0 animated:NO];
}
}
Upvotes: 2
Reputation: 1416
Make iCloudTeavitused
the delegate of your alertView by writing:
alertView.delegate = self;
upon alertView creation.
Upvotes: 0