日历数组 [英] Array of Calendars

查看:45
本文介绍了日历数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的应用程序使用的EKCalendars制作了一个NSMutableArray.在第一次启动时,我从EventStore导入所有日历,但不包括Birthdays日历和默认Calendar,仅保留用户创建的日历.但是,问题在于是否只有生日日历和默认日历.这就是我到目前为止所拥有的...

I've made a NSMutableArray for the EKCalendars that my application uses. On the first launch I import all the calendars from the EventStore but I exclude the Birthdays calendar and the default Calendar, leaving only the user created calendars. However the problem is if there is only Birthdays calendar and the default Calendar. Heres what i've got so far...

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);
            }
        }
    }

我有点困惑.任何帮助将不胜感激.

I'm a little stumped. Any help would be appreciated.

推荐答案

我已经在原始for循环之后添加了它.这样可以确保数组中有内容.

I've added this after the original for loop. This ensures that there is something in the array.

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);
             }
         }
     }
 }

问题不是for循环,而是空数组.

The problem was not for loop it was the empty array.

这篇关于日历数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆