An EKEventViewController object displays the details of a calendar event. You can set whether users are allowed to edit the event. If the event is an invitation, where the organizer is not the user, you can set whether a calendar preview is shown.
#pragma mark - #pragma mark EKEventEditViewDelegate
// Overriding EKEventEditViewDelegate method to update event store according to user actions. - (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action { RootViewController * __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.tableView reloadData]; }); } }]; }
// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar. - (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller { returnself.defaultCalendar; }
并且他的实现过程是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#pragma mark - #pragma mark Add a new event
// Display an event edit view controller when the user taps the "+" button. // A new event is added to Calendar when the user taps the "Done" button in the above view controller. - (IBAction)addEvent:(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]; }