IOS 6.1.2. Why won't UIAlertView be fired? the background is still on the screen

here is my code:

UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError show];

when I click the OK button, there is still a background indicator, and I press the screen, the status bar is flickering.

I found several answers, but they do not work, I changed my code to:

dispatch_async(dispatch_get_main_queue(), ^{
       UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
       [someError show];
});

or set delegate:

dispatch_async(dispatch_get_main_queue(), ^{
       UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:self cancelButtonTitle: @"ok" otherButtonTitles: nil];
       [someError show];
});

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [alertView dismissWithClickedButtonIndex:buttonIndex animated:NO];
    });

}

it still does not work, then I try:

UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"error" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];

doesn't work, crazy, this doesn't work either:

[self performSelectorOnMainThread:@selector(showAlert:) withObject:@"error", nil)  waitUntilDone:NO];

// the show Alert function
-(void)showAlert:(NSString*)str
{
    UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message: str delegate: nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
    [someError performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
}

still not working.

before and after warning:

before the alert showafter tap ok

+5
source share
4 answers

Make sure your view controller (or wherever you create your UIAlertView) has a " <UIAlertViewDelegate>" defined in the @interface line. For instance:

@interface YellowViewController : UIViewController <UIAlertViewDelegate>

, UIAlertView , .

. :

dispatch_async(dispatch_get_main_queue(), ^{
       UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:self cancelButtonTitle: @"ok" otherButtonTitles: nil];
       [someError show];
});

( ):

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [alertView dismissWithClickedButtonIndex:buttonIndex YES];
}

, , . , Apple "clickedButtonAtIndex:" :

.

, .

+3

UIKit , , alertView . , , , .

+1

, , , . , , , , , "SVProgressHUD" "MBProgressHUD". , WINDOW, , UIAlertView , , Picker Controller .. - , , , . , .

0

Well, I suffered too. I tried everything but did not work. Here, what worked for me, I hope it will be useful to you too.

Write a UIAlertView delegate method and place a breakpoint on it.

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

Now resume work and you will notice that the fog effect has disappeared. Therefore, just set a delay of 0.5 s in this deletion and, hopefully, your problem will be solved. Well, that worked for me.

Write a UIAlertView delegate method and place a breakpoint on it.

[NSThread sleepForTimeInterval:0.5];
0
source

All Articles