Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EKEventEditViewActionDeleted called several times while deleting event

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...

like image 637
Dilip Rajkumar Avatar asked Dec 21 '25 07:12

Dilip Rajkumar


1 Answers

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) {
    }
    ...
}
like image 143
Michael Peterson Avatar answered Dec 22 '25 22:12

Michael Peterson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!