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?
Asked
Active
Viewed 314 times
1
-
u can create custom navigation bar button items – Wings Mar 30 '18 at 13:12
-
What is the other Item for in the right button items ? – Nitish Mar 30 '18 at 13:12
-
@Nitish it is just a test button – ToniTJK Mar 30 '18 at 14:05
-
Add a Flexible space item as well in between the two. – Nitish Mar 30 '18 at 14:07
-
I did it, I had two navigator controllers so I just delete one and it's works. Thanks for your comments. – ToniTJK Mar 30 '18 at 14:21
1 Answers
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