1

I'm working on an app which relies on EventKit and calendar events and I'm having problems with editing of selected events. I'm using a Navigation View and I want to push an EKEventViewController (by interfacing with UIKit) for selected events.

The goal is to present the same view that is presented in Apples iOS calendar when an event is selected, shown in the image below.

iOS Calendar

I'm able to push the view and present the details about the selected event, but I'm missing some functionality and I have no clue how to make it work.

  1. I want the top navigation to show (top marked rectangle in the image). I can't event get the "Edit" button to show, even though I've set "allowsEditing" to true.
  2. I want the "Delete" button to show (bottom marked rectangle in image). For some events the "Delete" button will be replaced with buttons to accept/decline invitations.

Below you will find a snippet of my current code:

Main View

ForEach(events) { event in
            NavigationLink(destination: EventEditView(event: event, eventStore: eventsRepository.eventStore)) {
                EventRow(event: event)
            }
        }

UIView

struct EventEditView: UIViewControllerRepresentable {
    
    var event: EKEvent
    var eventStore: EKEventStore
    
    func makeUIViewController(context: Context) -> EKEventViewController {
        let viewController = EKEventViewController()
        
        viewController.event = event
        viewController.allowsEditing = true
        viewController.allowsCalendarPreview = true
        
        return viewController
        
    }
    
    func updateUIViewController(_ uiViewController: EKEventViewController, context: Context) {}

}

I'm fairly new to Swift and SwiftUI and have never done any interfacing with UIKit before, so any help is very much appreciated.

Thanks!

-UPDATE-
I've made some progress but I'm still not where I want to be. By changing the makeUIViewController function to the code below I'm able to present the "Edit" button and "Delete" button.

func makeUIViewController(context: Context) -> UIViewController {
        
        let viewController = EKEventViewController()

        viewController.event = event
        viewController.allowsEditing = true
        viewController.allowsCalendarPreview = true
        let navigationController = UINavigationController(rootViewController: viewController)
        
        return navigationController
}

My event view now looks like this: enter image description here

It's like I need to combine the top Navigation Bar from SwiftUI with the navigation from the EventViewController. I'm also getting the feeling that it tries to show the view as a modal sheet rather than pushing the view.

skegget
  • 111
  • 1
  • 7

0 Answers0