//create an EKEventEditViewController to display the event view controller.
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
//set eventstore global reference
addController.eventStore = self.eventStore;
// present EventsAddViewController as a modal view controller
[self presentModalViewController:addController animated:YES];
// assign <EKEventEditViewDelegate> to view controller
addController.editViewDelegate = self;
[addController release];
//======================================================================
//Add delegate methods
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
break;
case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
break;
default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
}
// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller
{
EKCalendar *calendarForEdit = self.defaultCalendar;
return calendarForEdit;
}