1

I am creating a new EKEventViewController with a event and display it afterwards

 let ekEventViewController = EKEventViewController(nibName: nil, bundle: nil)
 ekEventViewController.delegate = self
 ekEventViewController.allowsEditing = true
 ekEventViewController.event = event

 setViewController(ekEventViewController)

In setViewController I'm adding the new controller as a childViewController and the new controller's view as a subview. Now I would like to call the "EDIT" action immediately after presenting the EKEventViewController. I did not subclass anything, I just want to go to editing automatically using the EKEventEditingViewController.

So far I've tried several methods related to "editing".

I also tried to invoke the editButtonItem's Selector, but no success...

ekEventViewController.perform(ekEventViewController.editButtonItem.action!

Is there a way to accomplish this without subclassing? I was even thinking about reflection but couldn't figure it out...

Thanks in advance!

emmics
  • 994
  • 1
  • 11
  • 29

2 Answers2

1

Once you create your edit view controller, you just need to present it. Make sure you've defined your callbacks so you react appropriately when it dismisses itself - depending upon the action the user took (cancel, delete, add, modify):

   override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        let sourceArray = originalEventsList

        let eventViewController: EKEventEditViewController = EKEventEditViewController()
        eventViewController.event = sourceArray[indexPath.row]
        eventViewController.eventStore = self.eventStore
        eventViewController.editViewDelegate = self
        self.presentViewController(eventViewController, animated:true, completion:nil)
    }
Mozahler
  • 4,958
  • 6
  • 36
  • 56
  • Thank you for your answer. You were right, I didn't think about presenting this controller directly since I wanted the usual EKEventViewController being displayed after editing has finished, but it's fine this way for me. – emmics Aug 02 '17 at 15:18
  • Did upvote and it helped me a step, but unfortunately it's not the actual solution for my problem since I was trying to put it in a ViewController which is not full-screen, if you understand... – emmics Aug 02 '17 at 15:26
  • Of course. I upvoted your question. Happy you're making progress. That's why we're here. – Mozahler Aug 02 '17 at 15:41
1

Solution was to set the newly created EKEventEditViewController as my existing UINavigationViewController of my desired ViewController, since EKEventEditViewController is of type UINavigationController itself.

let newNC = EKEventEditViewController()
self.navigationController = newNC

Afterwards, set newNC as childViewController of your current root UIViewController and add its view as a subview.

emmics
  • 994
  • 1
  • 11
  • 29