过去的事件无法以编程方式显示在日历中

时间:2014-10-29 02:34:43

标签: ios iphone

我正在使用以下代码来处理过去的事件。请告诉我过去事件的解决方案

NSDate* endDate =  [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];
NSPredicate *fetchCalendarEvents = [store predicateForEventsWithStartDate:[NSDate distantPast] endDate:endDate calendars:nil];
NSArray *eventList = [store eventsMatchingPredicate:fetchCalendarEvents];
NSLog(@"allevent:%@",eventList);

1 个答案:

答案 0 :(得分:0)

请按照以下代码

  NSDate *endDate =  [NSDate dateWithTimeIntervalSinceNow:[[NSDate distantFuture] timeIntervalSinceReferenceDate]];

  NSArray *calendarArray = [NSArray arrayWithObject:cal];

  NSPredicate *fetchCalendarEvents = [eventStore predicateForEventsWithStartDate:[NSDate date] endDate:endDate calendars:calendarArray];

  NSArray *eventList = [eventStore eventsMatchingPredicate:fetchCalendarEvents];

  for(int i=0; i < eventList.count; i++)
  {

    NSLog(@"Event Title:%@", [[eventList objectAtIndex:i] title]);

  }