简体   繁体   English

当我在appdelegate swift中设置Tabbar时,如何设置viewcontroller的rootview?

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

I have set UITabBarController in AppDelegate and I have set the root view to tab bar object. 我在AppDelegate中设置了UITabBarController,并将根视图设置为tab bar对象。 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()
 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.

相关问题 如何在Swift ios的Tabbar Controller中设置rootview并在每个View Controller中显示Tabbar? - How to set rootview in tabbar controller and show tabbar in each view controller in swift ios? 在 appdelegate 中设置初始视图控制器 - swift - set initial viewcontroller in appdelegate - swift 如何在 Swift 中呈现 VC 并设置为新的 Root viewController? - How can I present VC and set as new Root viewController in Swift? 如何将设备令牌从AppDelegate.swift传递到ViewController.swift? - How can I pass device token from AppDelegate.swift to ViewController.swift? 单击按钮时如何设置 viewController 高度? - how can set viewController height when I click the button? 我有多个情节提要。 如何使用AppDelegate在另一个情节提要中打开另一个ViewController? (Segue) - I have multiple storyboards. How can I use AppDelegate to open another ViewController in another storyboard? (Segue) 如何设置NavigationController的根viewController - How can i set root viewController of NavigationController 如何在我的AppDelegate中设置一个引用初始化的Storyboard ViewController的变量 - How Do I Set A Variable In My AppDelegate That References The Initialized Storyboard ViewController 如何在AppDelegate上设置多个本地通知? - How can I set up multiple local notifications on my AppDelegate? 如何设置在 swift 5 中实例化后可以推送的初始 viewController - how can I set initial viewController that can push after instantiate in swift 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM