1
votes

In My storyboard, I have tab bar controller with three tableview controllers, each wrapped in a separate navigation controller and hooked to tab view controller. When the code runs initially the tab bar shows up with all tabs, but view controller display is black. Once a press a tab the appropriate controller shows up, but all tabs including the one I pressed disappear. If I continue to press the tab bar with approximate locations of the tabs then each controller comes up. But tab bar is empty. I tried setting tabbar isHidden to false, but no luck. Also why is the first time the controller display is black. How can I fix this?

Code:

extension ViewTabBarController: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
        let myVC1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "EVC") as! TableViewController1
        myVC.selectedTab = self.selectedTab

        let myVC2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PVC") as! TableViewController2

        let myVC3= UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TVC") as! TableViewController3

    let controllers = [myVC1, myVC2, myVC3,]

        self.viewControllers = controllers.map { UINavigationController(rootViewController: $0)}
    }
}
class ViewTabBarController: UITabBarController {
    var selectedTab:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = sell
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.tabBarController?.tabBar.isHidden = false
    }
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        self.selectedTab = (tabBar.items?.index(of: item))!
        print (self.selectedTab)

    }
1

1 Answers

0
votes

Try this it may helps you.

Is your storyboard in this way?? enter image description here

If yes then may the tabController as initial viewController. Like enter image description here