I have an UIAlertView
that pops up and displays a progress spinner while a specific action is being performed. That action has a callback method that programmatically dismisses the progress alert and pops up a new one saying the operation completed.
The ViewController acts as the delegate for the progress spinner alert, but programmatically calling dismissWithClickedButtonIndex
only sporadically fires. Is there something I'm missing or perhaps another way to accomplish what I'm going for (basically show spinner dialog and then alert that the operation completed)
Code
Progress Alert code
progressAlert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Progress Message"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil, nil];
progressAlert.tag = kAlertViewProgress;
[progressAlert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(progressAlert.bounds.size.width / 2, progressAlert.bounds.size.height - 50);
[indicator startAnimating];
[progressAlert addSubview:indicator];
[manager runOperation:parameters
successBlock:^(id response) {
// Callback should dismiss the progress dialog and then the delegate
// handler should show the second UIAlertView
// This only seems to call the delegate occasionally though
[progressAlert dismissWithClickedButtonIndex:0 animated:NO];
}];
Progress Alert dismissed
- (void)alertView:(UIAlertView*)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch (alertView.tag) {
case kAlertViewProgress:
if (buttonIndex == 0) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showCompletedAlert:@"Completed Message"];
});
} else if (buttonIndex == 1) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showCompletedAlert:@"Error Message"];
});
}
break;
}
}
Apparently the UIAlertView
is calling the willDismissWithButtonIndex
method, but does not call the didDismissWithButtonIndex
. Any clues about what is going on?
您是否在.h文件中设置了<UIAlertViewDelegate>
可能会帮助您
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.