Search code examples
iosswifteventkit

EKEventEditViewController doesn't dismiss


I'm presenting my EKEventEditViewController in a Helper-Class like this:

func showAddAppointmentController(withDate date:Date) {
    let eventVC = EKEventEditViewController()
    eventVC.editViewDelegate = self
    eventVC.eventStore = eventStore

    eventVC.event?.title = "Test appointment"
    eventVC.event?.startDate = date
    eventVC.event?.endDate = date.addingTimeInterval(3600)

    UIApplication.shared.keyWindow?.rootViewController?.present(eventVC, animated: true, completion: nil)
}

Everything works fine, the controller is shown, but as soon as I press "Add" or "Cancel", nothing happens but the following console output:

[EKCalendarItemLocationInlineEditItem isSubitemAtIndexSaveable:] - Location Inline Edit Item didn't have a text label on its non conference location cell; will return NO

I've implemented the delegate as follows, but the method isn't called (doesn't print and also the breakpoints don't work)

extension CalendarHelper : EKEventEditViewDelegate {
    func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) {
        print("Delegate called!")
        controller.dismiss(animated: true) {
            self.delegate?.didFinish()
        }
    }
}

Solution

  • Ok, the error was somewhere else and my bad. I was creating the CalendarHelper in the code and not holding it as a property of the class, so as soon as the calendar was shown, the helper was deleted and not available anymore as delegate.

    private var calendarHelper:CalendarHelper?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        calendarHelper = CalendarHelper(delegate: self)
    }
    
    func showCalendar() {
        calendarHelper.showCalendar()
    }
    

    instead of

    func showCalendar() {
        CalendarHelper(delegate: self).showCalendar()
    }