我在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()
答案 0 :(得分:0)
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()