0

I have UINavigationController with root UICalendarViewController. At some time while app running, inside UICalendarViewController I perform segue with UICalendarEventViewController. I keep reference to the 'UICalendarViewController' using

var calendarViewController: UICalendarViewController!

Later at some time I have an access to the UICalendarViewController, and then I need to dismiss UICalendarEventViewController. How to do this?

Inside UICalendarViewController I created

var calendarEventViewController: UICalendarEventViewController?

But when I try to dismiss it using:

calendarViewController.calendarEventViewController.dismissViewController(true, animated: true)

it doesn't work.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • Are you pushing the `UICalendarEventViewController` onto the navigation stack? I.e., are you using a 'push' segue? – Alex Jan 29 '15 at 11:59
  • yes, Segue: `Show (e.g. Push)` – Bartłomiej Semańczyk Jan 29 '15 at 12:00
  • In which case, you should be calling the dismissal from inside your `UICalendarViewController` via [delegation](https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html). You don't need the references that you have defined there. – Alex Jan 29 '15 at 12:02

1 Answers1

0

Sometimes for some reason we do not have the same instance of controller what we expect. In my case I didn't get the same instance of UICalendarViewController. But there is a way to do this if as me you use UITabBarController as a main navigation:

if let navigationController = viewControllersByIdentifier[PLContainerTabBarItemCalendar] as? UINavigationController {
        navigationController.popToRootViewControllerAnimated(true)
}

Then I have a current controller, and I can manage them with visible results.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358