使用EKEventEditViewController时崩溃

时间:2012-05-03 17:51:32

标签: cocoa-touch ios4 ios5

我有一个奇怪的崩溃,我不知道如何调试...... 这是代码:

-(void) addEventButtonPressed:(UIButton*)button{
DLog(@"Add new event");
// If event is nil, a new event is created and added to the specified event store. New events are 
// added to the default calendar. An exception is raised if set to an event that is not in the 
// specified event store.
// When add button is pushed, create an EKEventEditViewController to display the event.
EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];

// set the addController's event store to the current event store.
addController.eventStore = self.eventStore;
addController.editViewDelegate = self;

// present EventsAddViewController as a modal view controller
[self presentModalViewController:addController animated:YES];

}

我的应用程序在此行的一段时间后崩溃: [self presentModalViewController:addController animated:YES];

我正在使用ARC。 有线索吗? 谢谢!

我的控制台只说EXC_BAD_ACCESS(code=2, address=0xbf7ffff4)

[编辑]似乎需要先将eventStore初始化,然后再将其传递给addController,否则会导致崩溃。就我而言,它是零。

1 个答案:

答案 0 :(得分:1)

确保您从主线程呈现EKEventEditViewController;如果你从辅助线程中呈现它,它将崩溃(并不总是,但通常)。