1

I have to change / switch rootviewcontroller to user home page when login is success.

But when I change rootviewcontroller here I can't navigate to another page from buttons inside home view controller.

but when I restart the app, it works fine.

I will give the code below separately.

Login button action when user login is success (here I want to change the root view)

let mainStoryboard = UIStoryboard(name: StoryboardNames.mainStoryBoard, bundle: nil)
        let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: ViewController().classString()) as! ViewController
        let navController = UINavigationController(rootViewController: initialViewController)
        navController.isNavigationBarHidden = true
        self.view.window?.rootViewController = navController

This is what I give in AppDelegate and scene delegate to check if user in logged in and navigate to root view

let mainStoryboard = UIStoryboard(name: StoryboardNames.loginStoryboard, bundle: nil)
            let initialViewController = mainStoryboard.instantiateViewController(withIdentifier: LoginViewController().classString()) as! LoginViewController
            let navigationController = UINavigationController(rootViewController: initialViewController)
            navigationController.isNavigationBarHidden = true
            self.window?.rootViewController = navigationController
            self.window?.makeKeyAndVisible()

I am using a custom tab bar view controller as home view after login...the issue is with buttons inside child views of tab bar views.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jaseel.Dev
  • 730
  • 1
  • 7
  • 19
  • Are you basically just wanting to show a logon page if the use is not logged on? Or does each tab bar (in each nav controller) have completely different ViewControllers for each item? – SuperTully Feb 08 '21 at 23:09
  • I am able to show the tab bar with each controllers..the problem is I am not able to navigate to further views by clicking on buttons inside the tabs because navigation controller is nil after changing the rootview – Jaseel.Dev Feb 09 '21 at 03:40
  • Seems odd that you can have a nil rootviewcontroller? Have you tried instead setting a different tab bar controller as the nav controllers root controller? Or better yet, just switching out the viewcontrollers for each tab bar item? Also, how do you transition into the next viewcontroller in the nav stack, are you using segues or pushing controllers onto the stack? – SuperTully Feb 09 '21 at 20:18

0 Answers0