hidden Button on TabBar, second view.

Hi,

Ha have create one button in center the my tabbar, in the tabBarcontroller.swift.

I need Hidden this button in my second bar (viewcontroller), but i can't access the button for hidden.

how can i do this.

Code Block language
 var button = UIButton(type: UIButton.ButtonType.custom)
   
  override func viewDidLoad() {
    super.viewDidLoad()
     
    translateViews()
     
    let buttonImage = UIImage(named: "AddWhite48dp")
     
    button.frame = CGRect(x: 0.0, y: 0.0, width: buttonImage!.size.width, height: buttonImage!.size.height);
    button.setBackgroundImage(buttonImage, for: UIControl.State())
    button.backgroundColor = UIColor(red: 35.0/255.0, green: 49.0/255.0, blue: 57.0/255.0, alpha: 1)
    button.center = self.tabBar.center
    button.center.y -= self.tabBar.frame.height/3
    button.layer.cornerRadius = button.frame.size.width/2
    button.clipsToBounds = true
    button.addTarget(self, action: #selector(MainTabController.showMenu(_:)), for: UIControl.Event.touchUpInside)
    self.view.addSubview(button)
}
  func hiddenButton (hidden:Bool){
      button.isHidden = hidden
    }

I try create a func in my tabbarcontroller.swift.

but is not work for me. i can't access func in the second view.

Tks a lot.





You can access an item in the tab from its child views with:

Code Block
        let item0 = self.tabBarController!.tabBar.items![0]

But you cannot suppress items there by invoking setItems from the "child".
You then get a crash:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Directly modifying a tab bar managed by a tab bar controller is not allowed.'

I did not find how to hide item from there.

Maybe (I did not try), you could declare a Protocol with a func hideItem(row: Int)
It would execute in the TabBarController and be invoked from a child.
hidden Button on TabBar, second view.
 
 
Q