I have an app that programmatically saves an EKEvent to you iOS calendar. Instead of it going to the default calendar you choose the calendar you wish it to be placed in. I am having a problem with the way you are picking it because some calendars work but not others.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You are setting your event's calendar twice
[event setCalendar:c];
[event setCalendar:[[eventStore calendars]objectAtIndex:calendararray]];
Please tell me where do you get calendararray
is it an array? i seems more like an indexKey.
Instead of passign the index of your selected calendar, pass its title, like this: [calendar title]
or calendar.title
. then using this title look for the one in the complete list of edit and noneditable.
UPDATE
Just do something like this:
EKCalendar *theSelectedCalendar;
// selectedCalendarTitle comes from your delegate instead of your index...
for (EKCalendar *thisCalendar in eventStore.calendars){
if ([thisCalendar.title isEqualToString:selectedCalendarTitle]){
[event setCalendar:thisCalendar];
}
}
UPDATE 2
EKCalendar *theSelectedCalendar;
// selectedCalendarTitle comes from your delegate instead of your index...
for (int i=0; i<=([eventStore.calendars count]-1); i++) {
if ([[[[eventStore calendars]objectAtIndex:i] title] isEqualToString:selectedCalendarTitle]){
[event setCalendar:[[eventStore calendars]objectAtIndex:i]];
}
}
UPDATE 3
//Present the picker populated with the array: eventStore.calendars. This should return the index and store it in: indexOfSelectedCalendarFromEventSoreCalendars
if ([[[eventStore calendars] objectAtIndex:indexOfSelectedCalendarFromEventSoreCalendars] allowsContentModifications]){
[event setCalendar:[[eventStore calendars] objectAtIndex:indexOfSelectedCalendarFromEventSoreCalendars]];
} else {
NSLog(@"Selected calendar cannot be modified."); //Present the picker again for the user to select another calendar.
}