簡體   English   中英

iOS:如何獲取事件的標識符,該事件的標識符是通過調用EKEventEditViewController創建的

[英]iOS: How to get the identifier of an event, which was created via a call to EKEventEditViewController

在我的應用程序中,用戶可以創建事件。 這是通過向用戶展示用於創建事件的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];
             });
         }
     }];
}

因此,稍后我想檢索用戶創建的事件。 我當時在想,在某種程度上,在委托方法中,我可以獲得對新創建事件的引用?

還是有另一種方法來稍后僅提取用戶創建的事件?

為此,您需要首先創建一個新的EKEvent,保留對其的引用,並將其傳遞到EKEventEditViewController中:

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

在委托方法中,檢查EKEventEditViewActionSaved ,然后查閱self.newEvent來查找所需的事件。 如果要維護對事件的長期引用,可以存儲eventIdentifier或其他字段以供以后查找。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM