0
votes

So, My goal is to present the EKEventEditViewController to directly edit an event, without going through the "edit button" on the EKEventViewCOntroller.

I simply Wanna tap the event, and instantly open the EkEventEditViewController.

I've come far. It´s fetching the right Event and everything, and when I use the EKEventViewController It´s all working fine, however, when I call the EKEventEditViewController the event loads up inte editor with all the data (like startdate, title etc) but without the choice to pick Calendar. I also Can't save any changes when this happens.

I can Create new events however, so I know that It´s working in that perspective.

I also get this error message in console, but without the app crashing:

2020-09-26 00:36:30.795794+0200 MyCali[22214:848008] [EventEditor] -[EKCalendarItemLocationInlineEditItem isSubitemAtIndexSaveable:] - Location Inline Edit Item didn't have a text label on its non conference location cell; will return NO 2020-09-26 00:36:30.796328+0200 MyCali[22214:848008] Calendar: unable to save: (null)

here´s the code for calling the EKEventEditViewController:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    func editEventViewController() {
           
        
        let calendar1 = Calendar.current
        var dateComponents = DateComponents.init()
        dateComponents.day = 1 // days from today
        
        
        
        let futureDate = calendar1.date(byAdding: dateComponents, to: calendar.today!)
        
        let eventsPredicate = eventStore.predicateForEvents(withStart: calendar.today!, end: futureDate!, calendars: nil)
        
    
        let fetchedEvents = eventStore.events(matching: eventsPredicate)
        
        dateFormatter.dateFormat = "yyyy-MM-dd-hh:mm"
        
        let eventVC = EKEventEditViewController()
        let eventID = String(fetchedEvents[indexPath.row].eventIdentifier)
        
        eventVC.event = eventStore.event(withIdentifier: eventID)
        eventVC.editViewDelegate = self // don't forget the delegate

        present(eventVC, animated: true)
 
        
    }

the picture shows the Cannot Save statement. Also note that the Calendar line is not there

1

1 Answers

1
votes

This was stupid of me, but I'll share the answer if anyone (less likely) stumbles upon this. I had forgotten to set the Eventstore.

The evenstore is where the events are stored (the Calendar). So by not setting this, my event had no calendar to store itself into upon being edited, thus I got this error message.

All I did to solve this was adding:

EventVC.eventStore = eventStore