3

I am trying to save an event to iPhone calendar also to delete when user deletes the event. following is the code I am using for creating and editing an event .

// Upon selecting an event, create an EKEventViewController to display the event.
EKEventEditViewController *editController = [[EKEventEditViewController alloc] init];
editController.event =  [eventsList objectAtIndex:indexPath.row];
editController.eventStore = self.eventStore;
editController.editViewDelegate = self;
itsSelectedReminder = indexPath.row;
isReminderDeleted = TRUE;
[editController.navigationBar setTintColor:[UIColor colorWithRed:67/255.0 green:114/255.0 blue:18/255.0 alpha:1]]; 
[self presentModalViewController:editController animated:YES];

[editController release];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

Then When the user does any action add, edit or delete I am catching the event using the follwoing code.

- (void)eventEditViewController:(EKEventEditViewController *)controller 
          didCompleteWithAction:(EKEventEditViewAction)action {

It works perfect for add and edit however when I tried to delete It is calling the method several times so that makes my app crash. Any help is greatly appreciated. Please help as soon as possible.

Thanks in advance

Regards,

Dilip...

beryllium
  • 29,669
  • 15
  • 106
  • 125
Dilip Rajkumar
  • 7,006
  • 6
  • 60
  • 76
  • 2
    in iOS 5.1, I'm getting up to 4 calls when deleting and saving. When I add a new event, just 1. Checking the pointer from the controller I find out that some times its different even in the same array of calls. – the Reverend Mar 12 '12 at 15:57
  • Do you know how to fix it.. even now in my app it is like that...I dont know why it is doing like that... – Dilip Rajkumar Mar 13 '12 at 01:52
  • 4
    I just set the controller editViewDelegate = nil on the first call. Seems to be working. I double checked with the static analyzer and instruments for leaks, but there were none – the Reverend Mar 13 '12 at 14:49

1 Answers1

1

Set the editViewDelegate of the controller to nil immediately on completion.

func eventEditViewController(controller: EKEventEditViewController, didCompleteWithAction action: EKEventEditViewAction) {

    // prevent additional calls for the same action
    controller.editViewDelegate = nil 

    // whatever else you want to do
    dismissViewControllerAnimated(true) {
    }
    ...
}
Michael Peterson
  • 10,383
  • 3
  • 54
  • 51