I'm using a tabBar controller to control three viewControllers and want to set the navigationBar hidden only on two viewControllers, but it's not working.
picture of the structure of the tabBarController and three controllers This is the current tabBarController and viewControllers. I have a viewController for my tabBar Controller, and I set a navigationBar on that viewController
class PlayerTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
configureNavBar()
}
func configureNavBar() {
let backButton = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 10))
backButton.setImage(UIImage(named: "leave 1"), for: .normal)
backButton.addTarget(self, action: #selector(onBackPressed), for: .touchUpInside)
let barBackButton = UIBarButtonItem(customView: backButton)
self.navigationItem.leftBarButtonItem = barBackButton
}
@objc func onBackPressed() {
self.navigationController?.popViewController(animated: true)
}
}
TeamViewController is the screen that I want to show the navBar, so I'm not doing anything to that viewController, and I'm using this code to hide the navBar in other two controllers(timerView and rankingView)
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
The problem is that when I go to one of the two controllers, the navBar is hidden, but the navBar is visible when I move between the two screens(timer and ranking). For example, when I go to the timer or ranking screen from team screen, it works. But when I move from timer to ranking, the navBar is visible on the ranking screen and vice versa. How can I fix this problem?