日历数组
问题描述:
我为我的应用程序使用的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);
}
}
}
我有点难住。任何帮助,将不胜感激。
答
我在原始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);
}
}
}
}
问题不是循环它是空的数组。
你的应用崩溃了吗?那有什么问题?如果唯一的日历是生日,订阅或“日历”,则为 – 2011-12-16 14:26:51
。之后当我尝试使用数组时,应用程序崩溃。 – 2011-12-16 14:30:47