我在代码中创建了一个UITabBarController,这是我的代码
var recordsVC = SearchStamViewController()
recordsVC.tabBarItem = UITabBarItem(title: "Records", image: nil, selectedImage: nil)
var stationsVC = StationsSeachViewController()
recordsVC.tabBarItem = UITabBarItem(title: "stations", image: nil, selectedImage: nil)
var peopleVC = PeopleSearchViewController()
recordsVC.tabBarItem = UITabBarItem(title: "people", image: nil, selectedImage: nil)
//self.tabBarController?.setViewControllers([stationsVC , recordsVC], animated: true)
self.setViewControllers([recordsVC , peopleVC , stationsVC], animated: true)
self.selectedIndex = 1
self.view.backgroundColor = UIColor.whiteColor()
我在我的viewController中的ViewDidLoad中调用了哪个子UITabBarController。 我的tabbar没有显示所有tabBar项目标题,laso它以错误的方式显示它们(绿色backGround用于SearchStamViewController而不是SearchStamViewController !!)
怎么了?!答案 0 :(得分:0)
我已更新您的代码
var recordsVC = SearchStamViewController()
recordsVC.tabBarItem = UITabBarItem(title: "Records", image: nil, selectedImage: nil)
var stationsVC = StationsSeachViewController()
stationsVC.tabBarItem = UITabBarItem(title: "stations", image: nil, selectedImage: nil)
var peopleVC = PeopleSearchViewController()
peopleVC.tabBarItem = UITabBarItem(title: "people", image: nil, selectedImage: nil)
self.setViewControllers([recordsVC , peopleVC , stationsVC], animated: true)
self.selectedIndex = 1
self.view.backgroundColor = UIColor.whiteColor()
答案 1 :(得分:0)
我发现了问题,我没有启动新的UITabBarItem 而是
var recordsVC = SearchStamViewController()
recordsVC.tabBarItem.title = "Records"