Reputation: 617
I am setting rootViewController like this in my app.
func setupMainView() {
let rootViewContorller = window?.rootViewController
if (rootViewContorller?.presentedViewController != nil || rootViewContorller?.presentingViewController != nil) {
rootViewContorller?.dismiss(animated: false, completion: nil)
}
let tabbarController = UITabBarController()
tabbarController.delegate = self
let homeViewController = HomeViewController()
let rewardsViewController = RewardsViewController()
let homeNVc = UINavigationController()
let rewardsNVc = UINavigationController()
homeNVc.viewControllers = [homeViewController]
rewardsNVc.viewControllers = [rewardsViewController]
tabbarController.viewControllers = []
tabbarController.viewControllers = [homeNVc, rewardsNVc]
tabbarController.selectedIndex = 0
self.window?.rootViewController = tabbarController
}
It is working fine. But I have to change rootViewController in the app like after registration etc. After that When I go to Debug View Hierarchy
. I still see the registrationViewController there. And lets say If I change rootViewController 3-4 times all previous controllers are still there. So my question is How can I remove all viewControllers from memory before changing the rootViewController.
Upvotes: 0
Views: 269
Reputation: 702
You can call this function this will clear all viewcontrollers.
self.window?.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
Upvotes: 1