concept new event in category ios

appears as: new event, new events
iOS 4 in Action: Developing iPhone and iPad Apps

This is an excerpt from Manning's book iOS 4 in Action: Developing iPhone and iPad Apps.

Listing 16.1. Adding a new event to Calendar’s database
Listing 16.3. Using EventEditViewController and delegate to add a new event

The access to Calendar’s database is done by a few lines of code. You initialize the event store [[EKEventStore alloc] init] and define Calendar for data access [self.eventStore defaultCalendarForNewEvents] . As mentioned earlier, it’s a good practice to keep one event store around for all the data access. dealloc reminds you to release the memory when the view controller is released. The new thing you learned for using Event Edit view controller is all in addEvent and the delegate method -(void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action . You define the Event Edit view controller’s event store and delegate and then present the modal view controller [self presentModalViewController:addControlleranimated:YES] . When the user finishes editing the new event, the method [controllerdismissModalViewControllerAnimated:YES] will dismiss the edit view and save the new event to the Calendar.

Now let’s build and run it. When the application launches, click the Add button to present the Event Edit view controller. As you can see in figure 16.6, the new event’s Title, Location, Starts, Ends, Repeat, and Alert options are editable.

Figure 16.6. EventEditViewController presented as a modal view controller

Congrats! You just created a new event and saved it successfully to the local Calendar with the Event Kit UI framework! Now let’s talk about how to fetch the existing events from the Calendar’s database.