UIAlertView and UIActionView disappear - app left in inconsistent state
I've just added a UIAlertView to confirm a download action.
Once the user clicks OK, I then call a method (via the UIAlertView delegate method) to put up a UIActionSheet with a progress bar. Once the download has completed I dismiss the UIAlertView.
Since adding the UIAlertView I get a dimmed screen when the UIActionSheet is dismissed. I can't tap anything on the screen but the app doesn't seem to have crashed (e.g. EXC_BAD_ACCESS).
The only thing I've seen similar to this (i.e. where the screen dimmed) was when a notification wasn't being posted on the main thread (which I'm doing here).
Any suggestions?
==== UPDATE ====
// In my start Download method...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Your Download" message:[NSString stringWithFormat:@"Do you want to download this"] delegate:self cancelButtonTitle:@"Canc开发者_运维百科el" otherButtonTitles:@"Download", nil];
alert.tag = CONFIRM_DOWNLOAD;
[alert show];
// Then, in the UIAlertView delegate method...
- (void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag == CONFIRM_DOWNLOAD) {
if (buttonIndex == 0) {
DebugLog(@"Cancel download");
}
else {
DebugLog(@"Download");
[self startDownload];
}
}
}
See the following related question and its accepted answer:
UIActionSheet from UIAlertView
Basically, you need to use the
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
delegate method instead of the
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method. This allows the alertView to completely dismiss, instead of being stuck in that intermediate state that you are seeing where the partially dimmed cover view remains. I don't know for sure, but it probably has something to do with attaching your action sheet to the cover view before it has a chance to be removed, instead of getting attached to the underlying view that you were aiming for.
精彩评论