1

I'm using UIAlertView with "please wait" and UIActivityIndicatorView. I show it using

{
    ...
    [self performSelectorInBackground:@selector(sh) withObject:nil];
    //i've tried also
    //[NSThread detachNewThreadSelector:@selector(showWaiting) toTarget:self withObject:nil];
    ...
}

- (void)showWaiting {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [waitingAlert show];
    [pool drain];
}

When alert appears, screen becomes darkened and inactive. And when time to dismiss alert comes I do

[waitingAlert dismissWithClickedButtonIndex:0 animated:NO];

After this alert disappears, but sometimes (chance is about 5%) screen remains as before darkened and inactive. Has someone faced such problem? Thanks!

Valera
  • 111
  • 1
  • 5

3 Answers3

3

This isn't the answer you're looking for... but it's the "correct" answer and will save you some time in the long run:

You're misusing UIAlertView. It shouldn't be used for progress indicators and "Please Wait" dialogs. It's designed to be dismissed by the user hitting a button -- a UIAlertView should never, ever just disappear on its own (correction: actually, it can; Apple's API supports dismissing of it. But such a thing should be used very carefully.)

If you continue to abuse UIAlertView that way, don't be surprised when your app is rejected during app store submission and you then have to redo it another way.

Please see also my answer to this question:

Multiple AlertViews - Remove the alertview that is behind another alertview

Community
  • 1
  • 1
occulus
  • 16,959
  • 6
  • 53
  • 76
1

As occulus states avoid using UIAlertView like this,

I recommend MBProgressHUD, it's very easy to use, looks great and is designed for this purpose.

Alex
  • 2,513
  • 5
  • 27
  • 42
0

You have to create, show and release the alert outside the NSAutoreleasePool. For example, you make your call in background:

...
[NSThread detachNewThreadSelector:@selector(showWaiting) toTarget:self withObject:nil];
...

And the call has an autorelease pool:

- (void)showWaiting {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [self performSelectorInMainThread:@selector(showMyAlert) withObject:nil waitUntilDone:NO];
    //[waitingAlert show];
    [pool drain];
}

Then you must to show the alert using the main thread.

- (void)showMyAlert {
    UIAlertView * myAlert = [[UIAlertView alloc] initWith...]; 
    [myAlert show];
    [myAlert release];
}

If you try to show the alert inside the autorelease pool and this is drained then the alert dissapears.

I hope this helps!

LPL
  • 16,827
  • 6
  • 51
  • 95
Mr Spiegel
  • 66
  • 5