我正在尝试将一些事件保存到标准日历,然后为它们保存eventIdentifier,以便我以后可以更改/删除它们,但是,当我尝试将eventIdentifier保存到数组时,应用程序会抛出一个例外,说它没有。 这是我的代码:
int i,j;
for (i=0; i<[self.tableView numberOfSections]; i++){
for (j=0; j<[self.tableView numberOfRowsInSection:i]; j++){
NSString *title =[self getTitleInSection:i forRow:j];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSDate *myDate = [formatter dateFromString:[self getActionDate:i]];
EKEventStore *store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = title;
event.startDate = myDate;
event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
if (self.parameters.count==7){
NSMutableArray *eventIdArray = [[NSMutableArray alloc] initWithObjects: nil];
[self.parameters addObject:eventIdArray];
}
[[self.parameters objectAtIndex:7] addObject:event.eventIdentifier]; //this is so you can access this event later
}];
}
}
它抛出的异常是
2014-08-05 16:23:27.216 fazendoMinhaFesta [2544:e403] *由于未捕获的异常终止应用&#39; NSInvalidArgumentException&#39;,原因:&#39; * - [__NSArrayM insertObject:atIndex:]:object不能为nil&#39;
并突出显示该行
[[self.parameters objectAtIndex:7] addObject:event.eventIdentifier];
说线程9:信号SIGABRT
所以我猜测事件或event.eventIdentifier都是零,但我无法弄清楚原因。
有没有什么可以使他们成为零?
(我已经检查了,myDate和title是他们应该的价值)