簡體   English   中英

當我在appdelegate swift中設置Tabbar時,如何設置viewcontroller的rootview?

[英]How can I set rootview of a viewcontroller when I have set Tabbar in appdelegate swift?

我在AppDelegate中設置了UITabBarController,並將根視圖設置為tab bar對象。 但我需要將根視圖設置為另一個視圖控制器而不會丟失標簽欄的功能。 我怎樣才能做到這一點?

  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()
 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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM