iOS:如何获取事件的标识符,该标识符是通过调用EKEventEditViewController创建的

时间:2014-03-18 12:48:36

标签: ios events calendar reminders

在我的应用中,用户可以创建活动。这是通过向用户呈现用于创建事件的iOS UI来实现的:

    - (IBAction)addTermin:(id)sender
    {
        // Create an instance of EKEventEditViewController
    EKEventEditViewController *addController = [[EKEventEditViewController alloc] init];

    // Set addController's event store to the current event store
    addController.eventStore = self.eventStore;
        addController.editViewDelegate = self;
        [self presentViewController:addController animated:YES completion:nil];
    }

所以,我实现了委托方法:

    - (void)eventEditViewController:(EKEventEditViewController *)controller
      didCompleteWithAction:(EKEventEditViewAction)action
   { 
        MRHomeViewController * __weak weakSelf = self;
    // Dismiss the modal view controller
    [self dismissViewControllerAnimated:YES completion:^
     {
         if (action != EKEventEditViewActionCanceled)
         {
             dispatch_async(dispatch_get_main_queue(), ^{
                 // Re-fetch all events happening in the next 24 hours
                 weakSelf.eventsList = [self fetchEvents];
                 // Update the UI with the above events
                 [weakSelf.termineTableView reloadData];
             });
         }
     }];
}

所以,稍后我想检索用户创建的事件。我在想,在某个地方,不知何故在委托方法中,我可以获得对新创建的事件的引用?

或者是否有另一种方法可以稍后仅提取用户创建的事件?

1 个答案:

答案 0 :(得分:1)

要使其工作,您需要首先创建一个新的EKEvent,保留对它的引用,并将其传递给您的EKEventEditViewController:

    self.newEvent = [EKEvent eventWithEventStore:self.eventStore];
    addController.event = newEvent;

在委托方法中,检查EKEventEditViewActionSaved,然后咨询self.newEvent以了解您对该活动的需求。如果要维护对事件的长期引用,可以存储eventIdentifier或其他字段以供以后查找。