2011-12-16 25 views
1

我爲我的應用程序使用的EKCalendars製作了一個NSMutableArray。首次啓動時,我從EventStore導入所有日曆,但排除生日日曆和默認日曆,僅保留用戶創建的日曆。但問題是如果只有生日日曆和默認日曆。繼承人我到目前爲止...日曆數組

for (int i = 0; i < theEventStore.calendars.count; i++) 
    { 
     EKCalendar *c = [theEventStore.calendars objectAtIndex:i]; 
     if (c.type != EKCalendarTypeBirthday && c.type != EKCalendarTypeSubscription) 
     { 
      if (c.type == EKCalendarTypeLocal && [c.title isEqualToString:@"Calendar"]) 
      { 
       NSLog(@"Removed Calendar: %@", c); 
      } 
      else 
      { 
       [self.calendarLst addObject:c]; 
       NSLog(@"Added Calendar: %@", c); 
      } 
     } 
    } 

我有點難住。任何幫助,將不勝感激。

+0

你的應用崩潰了嗎?那有什麼問題?如果唯一的日曆是生日,訂閱或「日曆」,則爲 – 2011-12-16 14:26:51

+0

。之後當我嘗試使用數組時,應用程序崩潰。 – 2011-12-16 14:30:47

回答

0

我在原始for循環後添加了這個。這確保了數組中有某些東西。

int count = self.calendarLst.count; 
NSLog(@"Count: %i",count); 

if (count == 0) 
{ 
    for (int i = 0; i < theEventStore.calendars.count; i++) 
    { 
     EKCalendar *c = [theEventStore.calendars objectAtIndex:i]; 
     if (c.type == EKCalendarTypeLocal && [c.title isEqualToString:@"Calendar"]) 
      { 
       [self.calendarLst addObject:c]; 
       NSLog(@"Added Calendar: %@", c); 
      } 
     } 
    } 
} 

問題不是循環它是空的數組。