Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)
In section 11 of the 19th chapter of Cookbook, the problem is to display the calendar editing view that comes with iOS in the app.
The example code is to select the first calendar event that was found 1 years ago and then display it in the calendar editing view.
The calendar edit View controller is an instance object of Ekeventeditviewcontroller, which, as described in the book, has an event instance variable, and if it is not assigned a value before the controller is displayed, the value nil is a new view of the event, If you assign a specific event object to it, the view that edits the event is displayed.
The specific code is as follows:
-(void) displayeventeditcontroller{Eksource *icloudsource = [ SelfSourceineventstore: Self. EventstoreSourcetype:eksourcetypecaldav sourcetitle:@"ICloud"];if(!icloudsource) {NSLog(@"ICloud source don ' t exist!!!");return; } nsset *calendars = [Icloudsource calendarsforentitytype:ekentitytypeevent];NstimeintervalOneyear =1*365* -* -* -;NSDate*startdate = [[NSDateDate]datebyaddingtimeinterval:-O Neyear];NSDate*enddate = [NSDateDate]; Nspredicate *predicate = [ Self. EventstorePredicateforeventswithstartdate:startdate enddate:enddate Calendars:calendars. AllObjects];Nsarray*events = [ Self. EventstoreEventsmatchingpredicate:predicate];if(Events. Count>0) {Ekevent *event = events. Firstobject; Ekeventeditviewcontroller *controller = [Ekeventeditviewcontroller new]; Controller. Event= event; Controller. Editviewdelegate= Self; [ Self. NavigationcontrollerPresentviewcontroller:controller Animated:YESCompletion:Nil]; }}
However, when you actually run the app, you find that if you do not modify the select Done or cancel, there is no problem. If you modify and save the original event, an error will appear:
Calendarunable to save: (null)
But literally do not know is God horse place error!
The same event is not a problem to modify from the calendar app that comes with iOS.
Later, a document was found with the description: The Eventstore instance variable of the Calendar edit View controller must be set to the correct Stroe object, otherwise it cannot be saved.
Then insert the above code in the front of the display controller position in the following line:
controller.eventStore = self.eventStore;
Running the app again will now save the event as usual;)
iOS Programming cookbook The last example of the 19th chapter is a workaround that does not work correctly