我在我的应用程序中设置了这样的rootViewController。
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
}
工作正常。但我必须在注册后更改应用程序中的rootViewController等。之后当我转到Debug View Hierarchy
时。我仍然在那里看到registrationViewController。并且让我们说如果我改变rootViewController 3-4次所有以前的控制器仍然存在。所以我的问题是如何在更改rootViewController之前从内存中删除所有viewControllers。
答案 0 :(得分:1)
您可以调用此功能,这将清除所有viewcontrollers。
self.window?.rootViewController?.dismissViewControllerAnimated(false, completion: nil)