Iphone 当为eEntityTypeEvent请求AccessToEntityType时,MBProgressHUD对象不显示

Iphone 当为eEntityTypeEvent请求AccessToEntityType时,MBProgressHUD对象不显示,iphone,xcode,ios6,eventkit,ekevent,Iphone,Xcode,Ios6,Eventkit,Ekevent,我想显示MBProgressHUD对象-progressHud在进程中自动向日历添加大约100个事件。下面是我按按钮执行此任务时的代码 - (IBAction)add_event_for_test:(id)sender{ self.progressHud = [[MBProgressHUD alloc] initWithView:self.view]; self.progressHud.labelText = @"Adding some events to test";

我想显示MBProgressHUD对象-progressHud在进程中自动向日历添加大约100个事件。下面是我按按钮执行此任务时的代码

- (IBAction)add_event_for_test:(id)sender{
    self.progressHud = [[MBProgressHUD alloc] initWithView:self.view];
    self.progressHud.labelText = @"Adding some events to test";
    self.progressHud.detailsLabelText = @"Please wait...";
    [self.view addSubview:self.progressHud];
    [self.progressHud showWhileExecuting:@selector(add_more_event_execute:) onTarget:self withObject:nil animated:YES]; 
}
在下面的add_more_event_execute函数中,如果我试图请求访问eEntityTypeEvent的entity type以将新事件添加到iOS6中的日历中,则progressHud会立即显示和隐藏我需要显示progressHud,直到所有事件完全添加到日历。如果我不请求访问并在iOS5中运行它,progressHud工作正常

- (void) add_more_event_execute: (id)object{

    @autoreleasepool {
        eventStore=[[EKEventStore alloc] init];
        if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {

            // iOS 6 and later
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

                if (granted){
                // now add 100 event to calendar
                    int i = 0;
                    while (i < 100) {
                        EKEvent *addEvent=[EKEvent eventWithEventStore:eventStore];
                        NSString *tmp1 = @"Title iOS6: ";
                        tmp1 = [tmp1 stringByAppendingString:[NSString stringWithFormat: @" %d",i]];
                        addEvent.title = tmp1;

                        NSCalendar *calendar = [NSCalendar currentCalendar];
                        NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit ) fromDate:[NSDate date]];
                        [components setMonth:0];
                        [components setDay:i - 50]; //reset the other components
                        [components setYear:0]; //reset the other components
                        NSDate *dayi = [calendar dateByAddingComponents:components toDate:[NSDate date] options:0];
                        addEvent.startDate = dayi;
                        addEvent.endDate = [addEvent.startDate dateByAddingTimeInterval:600];
                        [addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];

                        NSError *err;
                        [eventStore saveEvent:addEvent span:EKSpanThisEvent error:&err];
                        if (err == nil) {
                            NSString* str = [[NSString alloc] initWithFormat:@"%@", addEvent.eventIdentifier];
                            NSLog(@"String iOS6 %d: %@ ngay:%@ ",i, str,addEvent.startDate);
                        }
                        else {
                            NSLog(@"Error %@",err);
                        }
                        i++;
                    } 
                }
                else
                {
                    //----- codes here when user NOT allow your app to access the calendar.
                }

            }];

        }
    }
}
-(void)添加更多事件执行:(id)对象{
@自动释放池{
eventStore=[[EKEventStore alloc]init];
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:完成:)])){
//iOS 6及更高版本
[eventStore requestAccessToEntityType:eEntityTypeEvent completion:^(已授予布尔,N错误*错误){
如果(授予){
//现在将100个事件添加到日历中
int i=0;
而(i<100){
EKEvent*addEvent=[EKEvent-eventWithEventStore:eventStore];
NSString*tmp1=@“标题iOS6:”;
tmp1=[tmp1 stringByAppendingString:[NSString stringWithFormat:@“%d”,i]];
addEvent.title=tmp1;
NSCalendar*日历=[NSCalendar currentCalendar];
NSDateComponents*components=[日历组件:(NSYearCalendarUnit | NSMonthCalendarUnit)fromDate:[NSDate日期]];
[组件设置月份:0];
[components setDay:i-50];//重置其他组件
[components setYear:0];//重置其他组件
NSDate*dayi=[calendar dateByAddingComponents:components toDate:[NSDate date]选项:0];
addEvent.startDate=dayi;
addEvent.endDate=[addEvent.startDate-Date-ByAddingTimeInterval:600];
[addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
n错误*错误;
[eventStore saveEvent:addEvent span:EKSpanThisEvent错误:&err];
如果(err==nil){
NSString*str=[[NSString alloc]initWithFormat:@“%@”,addEvent.eventIdentifier];
NSLog(@“字符串iOS6%d:%@ngay:%@”,i,str,addEvent.startDate);
}
否则{
NSLog(@“Error%@”,err);
}
i++;
} 
}
其他的
{
//-----当用户不允许您的应用访问日历时,请在此输入代码。
}
}];
}
}
}

请解释我的问题并给我一个解决方案。谢谢

[self.view将子视图带到前面:HUD];在self.progressHud=[[MBProgressHUD alloc]initWithView:self.view]之后添加此行;请不要忘记设置委派