【问题标题】:EKCalendar ErrorEKCalendar 错误
【发布时间】:2011-06-15 03:23:42
【问题描述】:

我有一个应用程序以编程方式将 EKEvent 保存到您的 iOS 日历中。与其转到默认日历,不如选择您希望放置的日历。我对您选择它的方式有疑问,因为某些日历有效,但其他日历无效。

【问题讨论】:

  • 当您保存到eventStoresetCalendar: 时出现该错误?
  • 当我尝试将事件保存到日历中时

标签: iphone objective-c xcode ipad calendar


【解决方案1】:

您正在设置活动的日历两次

[event setCalendar:c]; 
[event setCalendar:[[eventStore calendars]objectAtIndex:calendararray]]; 

请告诉我你从哪里得到calendararray 它是一个数组吗? i 看起来更像一个 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.
}

【讨论】:

  • 它们在 2 个单独的视图中,所以我使用了一个委托,它将选择器的行索引传输到 int calendarArray;
  • 你检查过变量的值吗?
  • “调试”您的应用程序并检查您的委托传输的变量的值是什么。你也可以在设置日历之前NSLog(@"%@",[[eventStore calendars]objectAtIndex:calendararray])吗?
  • 在修改中添加对象 if (thisCalendar.allowsContentModifications == YES){ NSLog(@"Calendar %lu can be modified.", (unsigned long)counter); [arrayColors addObject:cal];
  • 不传索引,传日历的名字,这样就可以找它代替使用objectAtIndex
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多