我有一个以编程方式将EKEvent保存到iOS日历的应用程序。而不是它进入默认日历,而是选择您希望将其放入的日历。我对您选择它的方式有疑问,因为某些日历有效但其他日历无效。
答案 0 :(得分:0)
您要将活动的日历设置两次
[event setCalendar:c];
[event setCalendar:[[eventStore calendars]objectAtIndex:calendararray]];
请告诉我你在哪里calendararray
它是一个阵列?我似乎更像是一个indexKey。
不是传递所选日历的索引,而是传递其标题,如下所示:[calendar title]
或calendar.title
。然后使用此标题查找编辑和不可编辑的完整列表中的那个。
<强>更新强>
做这样的事情:
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];
}
}
更新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]];
}
}
更新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.
}