Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dismissing a UIAlertView in ios 7 not working?

I'm trying to dismiss a UIAlertView before showing another and I found the answer here: iOS dismiss UIAlertView beforing showing another

The problem is that this is not working on iOS7 but works on iOS6.

This is working in iOS6

-(void)closePreviousAlert{
for (UIWindow* w in [UIApplication sharedApplication].windows)
    for (NSObject* o in w.subviews)
        if ([o isKindOfClass:[UIAlertView class]])
            [(UIAlertView*)o dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
}

Is there another solution for this?

like image 850
Goca Avatar asked Oct 23 '13 00:10

Goca


1 Answers

Your code is not valid in iOS7 because [UIApplication sharedApplication].windows doesn't have reference to UIAlertView since the UIAlertView itself is never added to any window in iOS7.

You need to keep reference to your actionSheet, this is best thing you can do.

You can do this with a reference to https://stackoverflow.com/a/19275311/1262634:

Class UIAlertManager = NSClassFromString(@"_UIAlertManager");
UIAlertView *alertView = [UIAlertManager performSelector:@selector(topMostAlert)];

Edit: this is a private API.

like image 140
Tarek Hallak Avatar answered Sep 27 '22 22:09

Tarek Hallak