1

I have set UITabBarController in AppDelegate and I have set the root view to tab bar object. But I need to set root view to another view controller without losing the functionalities of tab bar. How can I achieve that?

  let vc1 = ConstituencyViewController()
    //vc1.view.backgroundColor = UIColor.orange
    vc1.tabBarItem.title = "Search"
    vc1.tabBarItem.image = UIImage(named: "Search")

    // Set up the second View Controller
    let vc2 = ConstDetailViewController()
    //vc2.view.backgroundColor = UIColor.purple
    vc2.tabBarItem.title = "User"
    vc2.tabBarItem.image = UIImage(named: "Street View")

    // Set up the Tab Bar Controller to have two tabs
    let tabBarController = UITabBarController()

    tabBarController.viewControllers = [vc1, vc2]

    // Make the Tab Bar Controller the root view controller
    window?.rootViewController = tabBarController
    window?.makeKeyAndVisible()
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Rakesh Mohan
  • 601
  • 2
  • 11
  • 23

1 Answers1

1
 let appDelegate = UIApplication.shared.delegate as! AppDelegate

    let vc1 = ConstDetailViewController()
            //vc1.view.backgroundColor = UIColor.orange
            vc1.tabBarItem.title = "Search"
            vc1.tabBarItem.image = UIImage(named: "Search")

    let vc2 = OptionsViewController()

    vc2.tabBarItem.title = "Search"
    vc2.tabBarItem.image = UIImage(named: "Street View")

            // Set up the second View Controller

            //vc2.view.backgroundColor = UIColor.purple

            // Set up the Tab Bar Controller to have two tabs
            let tabBarController = UITabBarController()

            tabBarController.viewControllers = [vc1,vc2]
    appDelegate.window?.rootViewController = tabBarController
    appDelegate.window?.makeKeyAndVisible()
Rakesh Mohan
  • 601
  • 2
  • 11
  • 23
Vishal Sonawane
  • 2,637
  • 2
  • 16
  • 21