0

From some ViewController of my UINavigationController stack I present another ViewController and will never come back, but the problem is that deinit{} is not called. How should I remove each ViewController from the stack before navigation? Or should I use some other method? Now my code looks like

let destinationVC = storyboard?.instantiateViewControllerWithIdentifier("revealViewController") as! SWRevealViewController
self.presentViewController(destinationVC, animated: true, completion: nil)
JuicyFruit
  • 2,638
  • 2
  • 18
  • 35

1 Answers1

2

First of all, when you call presentViewController:animated:completion: you will present the new viewController modally, outside of the navigationController's hierarchy.

If you wish to present it within the navigationController hierarchy use:

self.navigationController!.pushViewController(destinationVC, animated: true)

And if you want to change the view hierarchy, the navigationController has a property viewControllers which can be set with or without animation.

self.navigationController!.setViewControllers([destinationVC],
           animated: true)

See the iOS Developer Library for more information.

Aerows
  • 760
  • 6
  • 22
  • It helped to deinit, but problem is that I want my destination ViewController not to be embedded in NavigationController (to be outside of its hierarchy): I have intro VCs, that won't be shown ever again until user quits app. – JuicyFruit Sep 13 '16 at 11:17
  • I see! =) Sounds like you have two different _view suites_ then. What I would do is to either just set the `rootViewController` property of your applications `UIWindow` to the desired `viewController`, or preferably having a _baseViewController_ that can perform the switch between the different *suites*. – Aerows Sep 13 '16 at 11:24
  • 1
    I've fixed my problem by adding `self.navigationController!.setViewControllers([], animated: false)` to `viewDidDisappear` method. Not sure if it is right approach but at least it works. – JuicyFruit Sep 13 '16 at 11:27