UIAlertViewDelegate didDismissWIthButtonIndex为1 UIAlertView调用,但不是另一个

时间:2013-11-11 23:44:59

标签: ios uialertview

(iOS7,xCode 5.1)我有一个应用程序,可以出于各种目的访问日历,我正在尝试将所有错误消息传递到位。

我有2 UIAlertviewsUIAlertviews两个都显示我需要它们时,但我只接到其中一个didDismissWIthButtonIndex的电话。名为_iCloudAlert的alertview是有效的。

如果我显示_iCloudAlert,则在点击按钮时会收到didDismissWIthButtonIndex的电话,但是当我显示_deniedAccessAlert时,我根本没有接听电话。我甚至看不到最外面的NSLog / s。

我的<UIAlertviewDelegate>文件中有.h

显示警报的代码,具体取决于日历访问:

// Check the authorization status of our application for Calendar
-(void)checkEventStoreAccessForCalendar
{

    NSLog(@"Check Status");
    EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];

    switch (status)
    {
            // Update our UI if the user has granted access to their Calendar
        case EKAuthorizationStatusAuthorized: [self accessGrantedForCalendar];
            NSLog(@"Already granted");
            break;
            // Prompt the user for access to Calendar if there is no definitive answer
        case EKAuthorizationStatusNotDetermined: [self requestCalendarAccess];
            break;
            // Display a message if the user has denied or restricted access to Calendar
        case EKAuthorizationStatusDenied:
        case EKAuthorizationStatusRestricted:
        {
            NSLog(@"already denied");
            [self performSelectorOnMainThread:@selector(showDeniedAccessAlert) withObject:nil waitUntilDone:NO];
        }

            break;

        default:
            break;
    }
}

两种警报视图方法:

- (void)informUserAboutCloud {

    _iCloudAlert = [[UIAlertView alloc]
                          initWithTitle: @"Important!"
                          message: @"If you have an iCloud account.....blah, blah, blah..."
                          delegate:self
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [_iCloudAlert show];

}

- (void)showDeniedAccessAlert {

    NSLog(@"Show Denied Access Alert");

    _deniedAccessAlert = [[UIAlertView alloc]
                          initWithTitle: @"Attention!"
                          message: @"It looks like you've blocked access to Calendar data... Blah, Blah, Blah..."
                          delegate: nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
    [_deniedAccessAlert show];

}

以下是用于对按钮点击执行操作的代码:

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex {

    NSLog(@"button index: %i", buttonIndex); //only logs when _iCloudAlert is shown
    NSLog(@"alertview: %@", alert); //only logs when _iCloudAlert is shown

    if (_iCloudAlert) {

        [self checkEventStoreAccessForCalendar];
        NSLog(@"check for calendar access from dismissed icloud alert...");

    } 

    if (_deniedAccessAlert) {

        NSLog(@"dismissed denied access..."); //never logged
    }
}

1 个答案:

答案 0 :(得分:2)

第二个UIAlertView的委托设置为nil。改变它,它会工作!