Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
560 views
in Technique[技术] by (71.8m points)

objective c - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...