UIAlertView间歇性地不调用委托方法

时间:2013-05-03 15:11:24

标签: ios objective-c uialertview

我正在弹出一个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];
         }];

Progress Alert被驳回

- (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。有关正在发生的事情的任何线索?

1 个答案:

答案 0 :(得分:1)

您是否在.h文件中设置了<UIAlertViewDelegate> 可能这会对你有所帮助