删除事件时多次调用EKEventEditViewActionDeleted

时间:2011-11-08 13:15:18

标签: iphone calendar ekeventkit

我正在尝试将事件保存到iPhone日历,以便在用户删除事件时删除。以下是我用于创建和编辑事件的代码。

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

然后当用户执行任何操作时添加,编辑或删除我正在使用以下代码捕获事件。

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

它非常适合添加和编辑,但是当我尝试删除时它会多次调用该方法,这会让我的应用程序崩溃。任何帮助是极大的赞赏。请尽快帮忙。

提前致谢

此致

...迪利普

1 个答案:

答案 0 :(得分:1)

完成后立即将控制器的editViewDelegate设置为nil。

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) {
    }
    ...
}