当我在 appdelegate swift 中设置 Tabbar 时,如何设置 viewcontroller 的根视图?
How can I set rootview of a viewcontroller when I have set Tabbar in appdelegate swift?
我已经在 AppDelegate 中设置了 UITabBarController 并且我已经将根视图设置为标签栏对象。但是我需要在不丢失选项卡栏功能的情况下将根视图设置为另一个视图控制器。我怎样才能做到这一点?
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()
我已经在 AppDelegate 中设置了 UITabBarController 并且我已经将根视图设置为标签栏对象。但是我需要在不丢失选项卡栏功能的情况下将根视图设置为另一个视图控制器。我怎样才能做到这一点?
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()