I have a storyboard setup like this:
Home Nav Controller - VC1 - VC2 - VC3 - VC4
Settings Nav Controller - VC1 - VC2 - VC3
To go between Home screens and Settings screens, I have a home icon/button in Settings VC1; and a settings icon/button in Home VC1. But I am not able to get this transition work correctly.
First I tried this code.
@IBAction func homeButtonTapped(button: UIButton) {
var navController: AppStoryboard.Main.instance.instantiateViewController(withIdentifier: "HomeNavController") as? UINavigationController
currentViewController?.present(navController!, animated: true, completion: nil)
}
//... similar code for settingsButtonTapped
It works fine. But this creates multiple view controller instances (checked Debug Memory Graph). Say I go back and forth between Home VC1 and Settings VC1 5 times, I see 5 instances of each view controller.
Then I tried this.
@IBAction func homeButtonTapped(button: UIButton) {
var navController: AppStoryboard.Main.instance.instantiateViewController(withIdentifier: "HomeNavController") as? UINavigationController
window?.rootViewController = navController!
}
//... similar code for settingsButtonTapped
This fixed the problem of multiple instances. But it messes up the custom animation popups I have. The popups work fine if I never ever click the Home or Settings button. But if I click the button once, from that points onwards the popups are not displayed correctly. Say I go from VC1 to VC2, and then open a popup in VC2. The popup appears, but the background is not greyed out like it usually is, and I can see the contents of VC2 clearly, and behind that I can actually see contents of VC1 too.
Any suggestion on how to get this working?
Thanks.