OGeek|极客世界-中国程序员成长平台

标题: iOS:如何获取通过调用 EKEventEditViewController 创建的事件标识符 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:35
标题: iOS:如何获取通过调用 EKEventEditViewController 创建的事件标识符

在我的应用中,用户可以创建事件。这是通过向用户展示用于创建事件的 iOS 用户界面来实现的:

    - (IBAction)addTerminid)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];
    }

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

    - (void)eventEditViewControllerEKEventEditViewController *)controller
      didCompleteWithActionEKEventEditViewAction)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];
             });
         }
     }];
}

所以,稍后我想检索用户创建的事件。我在想,在某个地方,以某种方式在委托(delegate)方法中,我可以获得对新创建事件的引用?

或者还有其他方法可以稍后仅获取用户创建的事件吗?



Best Answer-推荐答案


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

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

在委托(delegate)方法中,检查 EKEventEditViewActionSaved,然后查阅 self.newEvent 以找到您需要的有关事件的内容。如果您想维护对事件的长期引用,您可以存储 eventIdentifier 或其他字段以供以后查找。

关于iOS:如何获取通过调用 EKEventEditViewController 创建的事件标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22479903/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4