skip to Main Content

He everyone, I work on my project.
Below my storyboard and my old code.

I want to delete the Tabbar in the storyboard and created by code. I did it.

So if my tabBar is not set on any storyboard, how I can navigate from my login screen to my travels list screen without providing storyboard identifier?

Sorry for my English, I don’t speak English very well.

func goToNextScreen() {
        performSegue(withIdentifier: "GoToTravelListScreen", sender: userLoged)
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        if segue.identifier == "GoToTravelListScreen" {
            let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
            let listTravelVC = storyboard.instantiateViewController(withIdentifier: "mainTabBar") as! UITabBarController
            listTravelVC.modalPresentationStyle = .fullScreen
            self.present(listTravelVC, animated: true, completion: {
                let navController = listTravelVC.viewControllers![0] as! UINavigationController
                let vc = navController.topViewController as! TravelListViewController
                vc.userLoged = self.userLoged
            })
        }
    }

enter image description here

2

Answers


  1. After seeing your code and image you attached you need to put these lines

    // Login screen controller

    func goToNextScreen() {
            performSegue(withIdentifier: "GoToTravelListScreen", sender: userLoged)
        }
    

    put this code on login controller

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
    if segue.identifier == "GoToTravelListScreen" {
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let listTravelVC = storyboard.instantiateViewController(withIdentifier: "TravelListViewController") as! TravelListViewController
        
    listTravelVC.userLoged = self.userLoged
        self.navigation.pushviewcontroller(listTravelVC, animated: true)
    }
    }
    

    from above code you will use the login controller navigation stack

    Login or Signup to reply.
  2. You can use

    func goToNextScreen() {
        let tabBarController = UITabBarController()
        tabBarController.modalPresentationStyle = .fullScreen
        
        let travelListViewController = TravelListViewController()
        travelListViewController.userLogged = userLogged
        let navigationController = UINavigationController(rootViewController: travelListViewController)
        
        tabBarController.viewControllers = [navigationController]
        
        present(tabBarController, animated: true, completion: nil)
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search