2012-07-13 19 views
0

我知道EKEventStore類有@property NSArray *日曆,它返回一個事件存儲的日曆對象的數組,但我不知道如何訪問該數組內的特定日曆,當我知道的是日曆的標題。我可以在網上找到的唯一示例是訪問defaultCalendarForNewEvents的程序,但我想要的日曆不是默認日曆。我也不知道日曆的唯一標識符,我所知道的只是標題。我試圖使用valueForKey方法來訪問標題爲BART的日曆,但是我所做的絕對是錯誤的,任何人都可以幫忙嗎?這裏是我的嘗試:如何在Xcode中編寫一個程序來檢查是否存在特定的iCal日曆並訪問該日曆以添加事件?

@interface BARTClass:NSObject的{

EKEventStore *eventStore; 

EKCalendar  *bart 

NSArray   *calendars; 

}

@屬性(非原子,保留)EKEventStore * eventStore;

@property(nonatomic,retain)NSArray * calendar;

@property(nonatomic,retain)EKCalendar * bart;

- (EKCalendar)getBartCalendar;

@end

...

@implementation

@synthesize日曆,巴特,eventStore;

- (EKCalendar)getBartCalendar {

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

[self setCalendars = [eventStore calendars]]; 

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

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

...

回答

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

如果日曆「巴特」的存在,你在循環的結束得到它。

+0

非常感謝你@HeinerTiling,這對我很有幫助。 – user1521318 2012-07-17 17:35:31

相關問題