2011-11-08 44 views
3

我想保存事件到iPhone日曆也刪除當用戶刪除事件。以下是我用於創建和編輯事件的代碼。EKEventEditViewActionDeleted調用幾次,同時刪除事件

// 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 { 

它適用於添加和編輯,但是當我試圖刪除它多次調用方法,使我的應用程序崩潰。任何幫助是極大的讚賞。請儘快提供幫助。

在此先感謝

問候,

迪利普...

+2

在iOS 5.1中,我在刪除和保存時最多撥打4個電話。當我添加一個新的事件時,只需要1.檢查控制器的指針我發現,即使在相同的調用數組中,它的某些時候也是不同的。 –

+0

你知道如何解決它..即使現在在我的應用程序是這樣的...我不知道它爲什麼這樣做... –

+4

我只是在第一次調用時設置控制器editViewDelegate = nil。似乎工作。我再次用靜態分析儀和儀器檢查是否有泄漏,但沒有 –

回答

1

將控制器設置爲無立即完成editViewDelegate。

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