1

I want to add a bar button in a navigation controller, but when I put the button, it looks like it is behind the navigation controller. Someone knows what happens?

enter image description here


enter image description here

ToniTJK
  • 181
  • 1
  • 3
  • 11

1 Answers1

1

if you want to create it programmatically u can try this in ur view did load method

let rightBarButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(ViewController.myRightSideBarButtonItemTapped(_:)))
self.navigationItem.rightBarButtonItem = rightBarButton


let leftBarButton = UIBarButtonItem(title: "Edit", style: UIBarButtonItemStyle.done, target: self, action: #selector(ViewController.myLeftSideBarButtonItemTapped(_:)))
self.navigationItem.leftBarButtonItem = leftBarButton
//Mark - Call functions
func myRightSideBarButtonItemTapped(_ sender:UIBarButtonItem!)
{
    print("myRightSideBarButtonItemTapped")
}

func myLeftSideBarButtonItemTapped(_ sender:UIBarButtonItem!)
{
    print("myLeftSideBarButtonItemTapped")
}
Wings
  • 2,398
  • 23
  • 46
  • https://stackoverflow.com/questions/9273204/can-you-add-buttons-to-navigation-bars-through-storyboard OR here is the answer on stackoverflow to create it by using storboard – Wings Mar 30 '18 at 13:24
  • It works now, it was that I had two navigation controller. Thanks for your suggestions. – ToniTJK Mar 30 '18 at 18:02