0

在执行特定操作时,我有一个UIAlertView弹出并显示进度微调器。该操作有一个回调方法,它以编程方式关闭进度警报并弹出一个新的提示操作完成。

ViewController 充当进度微调器警报的委托,但以编程方式调用dismissWithClickedButtonIndex只会偶尔触发。是否有我遗漏的东西或者可能是另一种方式来完成我想要的(基本上显示微调框对话框,然后提醒操作完成)

代码

进度警报代码

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];
         }];

进度警报已关闭

- (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;
    }
}

更新

显然UIAlertView是调用willDismissWithButtonIndex方法,但不调用didDismissWithButtonIndex. 关于发生了什么的任何线索?

4

1 回答 1

1

你有没有<UIAlertViewDelegate>在.h文件中设置可能会对你有所帮助

于 2013-05-03T18:29:20.730 回答