问题描述
|
我有一个可以以编程方式将EKEvent保存到您的iOS日历的应用。而不是转到默认日历,而是选择希望放入的日历。我选择它的方式存在问题,因为某些日历可以工作,而其他日历却不能。
解决方法
您正在两次设置活动的日历
[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.
}