2013-02-28 81 views
0

在我的代码中我正在检索用户提醒并显示它们的tableview。 每当我在代码中打印NSLog时,表格数组得到正确显示。但是每当我在代码中遗漏了NSLog,我的数据就不能正确显示了。提醒“title”的值返回(null)。奇怪的数据解析问题

我可以每次重现该问题。任何人都知道这里发生了什么?在上面的代码才能使用的NSLog

- (void)shareReminderButtonAction:(UIButton *)buttonEvent { 

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

NSPredicate *predicate = [store predicateForRemindersInCalendars:nil]; 

[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) { 

    [store fetchRemindersMatchingPredicate:predicate completion:^(NSArray *reminders) { 

     ReminderView *shareRem = [[ReminderView alloc]init]; 

     NSLog(@"Reminders: %@", reminders); 

     UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:shareRem]; 
     [navigation setNavigationBarHidden:YES]; 

     [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:navigation animated:YES 
                        completion:^(void){[shareRem setArray:reminders];}]; 

    }]; 

}]; 

} 

日志数据:在的UITableViewController结束

"EKReminder <0x1d5b3630> {title = Gdghv; dueDate = 2013-03-06 22:00:00 +0000; completionDate = (null); priority = 0; calendarItemIdentifier = 0BD2CB76-588B-4103-86B0-D71D22317DC0}" 

日志数据在我的代码没有NSLog的接收上述数据时:

CADObjectGetInlineStringProperty failed fetching title for EKPersistentReminder with error Error Domain=NSMachErrorDomain Code=268435459 "The operation couldn\342\200\231t be completed. (Mach error 268435459 - (ipc/send) invalid destination port)" 

"EKReminder <0x1c5e6fd0> {title = (null); dueDate = (null); completionDate = (null); priority = 0; calendarItemIdentifier = (null)}" 

非常感谢!

+0

您使用不适当的标签*仅*恭喜... – 2013-02-28 22:58:17

+0

我发现我是有这个问题。 EKEventStore很快就会释放。我把它放在我的viewDidLoad方法中,一切都很好! – freshking 2013-03-01 09:25:09

回答

0

EKEventStore对象需要在您使用Event Kit对象的整个过程中保持不变。通常情况下,最好将它安置在单身人士身上。从Apple's docs

一种EKEventStore对象需要向 初始化和释放相对大量的时间。因此,您不应该初始化并为每个事件相关任务释放单独的事件存储。相反, 在您的应用加载时初始化单个事件存储,并重复使用它 以确保您的连接长期存在。

事件存储实例不得在其他事件工具包 对象之前释放;否则,可能会发生未定义的行为。