Home > other >  only one tab at a time showing up
only one tab at a time showing up

Time:07-30

I am unable to get each tab to show up before it is clicked, I tried setting each one to its own view controller then changing the title that way but it's still not working ( sorry if my formatting is off , this is by first post on here) thanks

    @objc func didTapButton(){
        // create and present tab bar controller
        let tabBarVC = UITabBarController()
        
        let vc1 = UINavigationController(rootViewController: FirstViewController())
        let vc2 = UINavigationController(rootViewController: SecondViewController())
        let vc3 = UINavigationController(rootViewController: ThirdViewController())
        
        vc1.title = "My Groups"
        vc2.title = "My Events"
        vc3.title = "Browse Events"
        
        tabBarVC.setViewControllers([vc1, vc2, vc3], animated: false)
        
        guard let items = tabBarVC.tabBar.items else{
            return
        }
        
        let images = ["bell", "star", "person"]
        
        for x in 0..<items.count{
            items[x].image = UIImage(systemName: images[x])
        }
        
        
        tabBarVC.modalPresentationStyle = .fullScreen
        present(tabBarVC, animated: true)
        
    }

Screenshot:

enter image description here

CodePudding user response:

As I can see from the screenshot, I think tabs are there but their image and selectedImage colors are the reason why you can't see tabs. Are you able to see them in view hierarchy?

CodePudding user response:

From the doc :

Configuring your tab bar programmatically:

To configure the tab bar associated with a UITabBarController object, configure the view controllers associated with the tab bar controller. The tab bar automatically obtains its items from the tabBarItem property of each view controller associated with the tab bar controller.

To configure tab bar items directly, use the setItems(_:animated:) method of the tab bar itself.

You can not use tabBar.items property directly as you do

  • Related