0

我知道 EKEventStore 类具有返回事件存储日历对象数组的@property NSArray *calendars,但是当我只知道日历的标题时,我不知道如何访问该数组中的特定日历。我可以在网上找到的唯一示例是访问 defaultCalendarForNewEvents 的程序,但我想要的日历不是默认日历。我也不知道日历的唯一标识符,我只知道标题。我尝试使用 valueForKey 方法访问名为 BART 的日历,但我所做的绝对是错误的,有人可以帮忙吗?这是我尝试过的:

@interface BARTClass : NSObject {

EKEventStore    *eventStore;

EKCalendar      *bart

NSArray         *calendars;

}

@property (nonatomic, 保留) EKEventStore *eventStore;

@property (nonatomic, 保留) NSArray *calendars;

@property(非原子,保留)EKCalendar *bart;

-(EKCalendar)getBartCalendar;

@结尾

...

@执行

@synthesize 日历、bart、eventStore;

-(EKCalendar)getBartCalendar {

[self setEventStore: [[EKEventStore alloc] init]];

[self setCalendars = [eventStore calendars]];

NSArray *titles = [calendars valueForKey:@"title"];

[self setBart:[titles valueForKey:@"BART"]];

...

4

1 回答 1

3

我想你已经接近目标了。

你可以这样做:

EKEventStore *eventStore = [[EKEventStore alloc]init];

EKCalendar *bart;

NSArray *myCals = [eventStore calendars];

for (int i=0; i < [myCalls count]; i++) {
    bart = [myCals objectAtIndex:i];
    if (bart.title isEqualToString:@"Bart"){
       break;
    }
    else {
      bart = nil;
    }
}

如果日历“Bart”存在,您将在循环结束时获得它。

于 2012-07-16T08:52:35.463 回答