EKEventEditViewController打开速度非常慢

时间:2013-10-24 22:46:03

标签: ios objective-c ekevent

我正在使用EKEventEditViewController来允许我的应用程序中的事件添加到iPhone日历中。这是我目前使用的代码:

    [self.store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (!granted) { return; }
        EKEvent *storedEvent = [EKEvent eventWithEventStore:self.store];
        storedEvent.title = self.selectedEvent.title;
        storedEvent.startDate = self.selectedEvent.date;
        storedEvent.endDate = [NSDate dateWithTimeInterval:60*60 sinceDate:self.selectedEvent.date];
        storedEvent.notes = self.selectedEvent.comments;
        [storedEvent setCalendar:[self.store defaultCalendarForNewEvents]];
        self.eventController.event = storedEvent;
        self.eventController.eventStore = self.store;
        self.eventController.editViewDelegate = self;
        [self presentViewController:self.eventController animated:YES completion:nil];
    }];

虽然我已预先安装了视图控制器和EventStore,但此代码需要花费10秒钟来生成必要的视图事件。有没有办法让这个更快,或者我只需要设置一个微调器并告诉用户等待?

1 个答案:

答案 0 :(得分:6)

将在任意队列上调用完成处理程序。 在完成块内部调度主线程上与UIKit相关的东西:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    self.eventController.event = storedEvent;
    self.eventController.eventStore = self.store;
    self.eventController.editViewDelegate = self;
    [self presentViewController:self.eventController animated:YES completion:nil];
}];