Reputation: 1063
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!
Upvotes: 1
Views: 2235
Reputation: 1063
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.
Upvotes: 1
Reputation: 5303
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)
}
Upvotes: 1