Amrmsmb
Amrmsmb

Reputation: 1

how to place a bar button on the navigation bar

I am following this tutorial, and I am trying to add a "bar button". the tutorial says the following :

While you’re there, change the title of the screen to Add Player (by double-clicking in the navigation bar). Also add two Bar Button Items to the navigation bar. In the Attributes inspector, set the Identifier of the button to the left to Cancel, and the one on the right to Done (also change this one’s Style from Bordered to Done).

I followed the steps, but every time i drag the "bar button" to place it on the navigation bar, it moves automatically to the lower left of the scene as shown in image-1

please let me know the following

1- how to place the bar button on the navigation bar

2- how to rename "Root View Controller" to "Add Player"

image-1:

enter image description here

Upvotes: 0

Views: 549

Answers (3)

KKRocks
KKRocks

Reputation: 8322

Disable translucent property of navigationBar of NavigationController in storyboard.

if you have enabled translucent then you not able drag bar item to navigationBar .

enter image description here

Now you able to drag Bar item to Navigation bar through story board.

Result enter image description here

Upvotes: 1

elk_cloner
elk_cloner

Reputation: 2149

Just do the following from the beginning.:(

Sorry to say that.

Take a view controller.embed it to navigation controller.

How?

Select your view controller and from enter image description here

then go to there and select bar button item and keep that bar button item to navigation bar.

enter image description here

Double click your navigation controller and write "Add player" for naming

enter image description here

i hope you get this.

Upvotes: 0

Gregga17
Gregga17

Reputation: 168

enter image description here

Change Students -> "Add Player". This wil rename "Root View Controller"

You can also set the bar button programmatically. Try this:

self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: #selecter(function), action: nil)

Upvotes: 0

Related Questions