1

(iOS7,xCode 5.1)我有一个应用程序可以出于各种目的访问日历,并且我正在尝试将所有错误消息都放在适当的位置。

我有 2 UIAlertviews。两者都UIAlertviews在我需要时显示,但我只接到didDismissWIthButtonIndex其中一个的电话。调用的警报视图_iCloudAlert是有效的。

如果我显示_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
    }
}
4

1 回答 1

2

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

于 2013-11-11T23:46:42.513 回答