In my app, the user can create events. This is achieved by presenting the user the UI of iOS for creating an event:
- (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];
}
So, I implement the delegate method:
- (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];
});
}
}];
}
So, later I want to retrieve the events a user has created. I was thinking , that somewhere, somehow in the delegate method, I can obtain a reference to the new created event?
Or is there another way to later fetch only events created by the user?
To make this work, you need to first create a new EKEvent, keep a reference to it, and pass it into your EKEventEditViewController:
In the delegate method, check for
EKEventEditViewActionSaved
and then consultself.newEvent
to find what you need about the event. If you want to maintain a longer term reference to the event, you can store theeventIdentifier
or other fields for later lookup.