Fervus
Fervus

Reputation: 720

crash when using EKEventEditViewController

I have a weird crash that I don't know how to debug... Here is the code:

-(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];

}

My app crashes after a looong time at this line: [self presentModalViewController:addController animated:YES];

I am using ARC. Any clues? Thanks!

My console says just EXC_BAD_ACCESS(code=2, address=0xbf7ffff4)

[EDIT] It seems eventStore needs to be initialized before passing it to addController or you get a crash. In my case it was nil.

Upvotes: 1

Views: 969

Answers (1)

Christopher King
Christopher King

Reputation: 1715

Make sure that you are presenting the EKEventEditViewController from the main thread; it will crash (not always, but usually) if you present it from a secondary thread.

Upvotes: 2

Related Questions