Cintu Cintu - 1 month ago 8
iOS Question

Inside tabbar viewcontrollers navigationbar changes not working from storyboard

I have created


NavigationController(Main) - > LoginViewController -> Tabbarviewcontroller -> HomeViewController


If I add barbutton item in HomeViewController through storyboard it's not displaying in simulator.

But I can see the changes in storyboard.

enter image description here

enter image description here

Title Home1 and barbutton item not displaying in simulator

Joe Joe
Answer

Try this Code: Tested in Swift 3:

Note: Delete all your barButtonItems and try below code.

Add this code to your Home1 VC:

override func viewWillAppear(_ animated: Bool) {
    let RightButtomitem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(handler)) 
    self.tabBarController?.navigationItem.rightBarButtonItem = RightButtomitem
}

func handler(sender:UIButton) {
    print("Add Button pressed")
}

Add this code to your Home2 VC:

override func viewWillAppear(_ animated: Bool) {
    let RightButtomitem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(handler)) 
    self.tabBarController?.navigationItem.rightBarButtonItem = RightButtomitem
}

func handler(sender:UIButton) {
     print("Done Button Pressed")
}

Output:

enter image description here