how to place a bar button on the navigation bar - ios

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:

Disable translucent property of navigationBar of NavigationController in storyboard.
if you have enabled translucent then you not able drag bar item to navigationBar .
Now you able to drag Bar item to Navigation bar through story board.
Result

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)

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
then go to there and select bar button item and keep that bar button item to navigation bar.
Double click your navigation controller and write "Add player" for naming
i hope you get this.

Related

black screen appears in the tab bar after navigation controller

if I press the third tab bar (tab bar index : 2), and it opens RequestVC, it will show a black screen like the picture below, so I can't see my label. and I don't know why the green icon in the bottom dissapears
I don't understand why this happens. I just uncheck "transculent" in the navigation bar, and in the NewRequestVC I also check "Hide Bottom bar on Push"
I recreate your storyboard, it's working fine for me.
Try these steps:
delete your navigation controller
embed your request VC in navigation controller
connect your main tab bar to navigation controller relationship segue as view controllers.
Try you restart Xcode?
If there is nothing wrong in storyboard then probably in your code.

Dragging Bar Button Item to Navigation Controller fails

I am following a tutorial on Udemy about Navigation Controllers.
The instructions are to drag a Navigation Controller onto the storyboard, and then drag and drop a Bar Button Item on the right of its navigation bar to segue to another view controller.
However, when I drag the Bar Button Item to its would-be position on the navigation bar, no drop-zone gets highlighted, and the button gets added to a random tab at the bottom of the screen.
I have tried finding references to this problem but all solutions are programmatic and given the wysiwyg nature of iOS development I would like to solve it through XCode UI.
Is there some setup I must change or is this an XCode 7 discrepancy?
Try to add a ViewController and then in Editor -> Embed in -> NavigationController. Then it should work.
I have solved my problem by dragging the Bar Button Item into the Document Outline, below Root View Controller.
This automatically creates Left Bar Button Items and Right Bar Button Items, which gives you an opportunity to drag the Item in the section of the controller you like.

How to Add a Bar Button Item on a Disappeared Navigation Bar using Storyboard?

I want to add a bar button item on the navigation bar. (Say View 1 here.) The view that will segue to View 1 is embedded in a navigation controller.
However, the navigation bar is not showing in this view.
If I use attribute inspector to add a opaque/ translucent navigation bar, there will be a navigation bar in View 1. But if I drag in a bar button item, it cannot be shown in the storyboard. Though the bar button is in the document outline, it cannot be shown on the storyboard. Also, if I run the application, it is not on the screen.
When running the application in the simulator, View 1 will have a navigation bar on the top of it, since I use "Show" rather than "Show Details" to show View 1. I tried to embed View 1 in a navigation controller again, but it won't help much.
Can anyone tell me how to add a bar button in this situation using storyboard? And why the navigation bar is missing from the storyboard?
Thanks in advance.
I figure it out by myself.
Drag a Navigation Item from the object list, and then add bar button item to it.
Thanks to rdelmar for his idea, though drag out a navigation bar won't work in the way I thought it should work.
In my situation, View 1 is a table view. Drag a navigation bar to the view will cause it to be the header view for the table, rather than a navigation bar I had expected. Then there will be two navigation bar in the view when I run the application.
Of course we can drag out a navigation bar and add a button to it, it might work different with your expectation. As I had said, it might leads to a view which contains two navigation bars.
You can fix this by drag out the Navigation Item (contains the bar button you had added) inside the Navigation Bar out. In my situation, I drag it out and put it the same level with the table view inside the document outline. Then it won't become the header view for the table view.
After that, we can just delete the navigation bar from the document outline.
I have no idea why the navigation bar disappears in my storyboard. If anyone has some idea for this, please let me know.
It sounds like you're adding the navigation bar by using the Simulated Metrics. If so, this doesn't add one at run time, it's only for layout purposes in IB. You should drag out a navigation bar from the objects list, and add your button to it.

Xcode - replace navigation bar with toolbar on show segue

This is what I wish to do.
---- Segue : show ---->
on the destination page, I want to hide the tab bar from the previous page and show the toolbar instead.
When I check "Hide bottom bar on push" on storyboard, the tool bar on the destination page disappears as well.
I think you should change the title of your question since you want to replace the tabBar with a toolBar and keep the navigationBar. At leas this is what I understand from your sketch.
As for the question, have you tried hiding the tabBar in viewWillDisappear in your first view?

Cannot add Bar Button to Second Page through Interface Builder

My App has two pages, so in interface builder I have three controllers:
A NavigationController
segues via RootViewController to TableViewController1
segues via push to TableViewController2
I easily added a Bar Button to the right side of the navigation bar of TableViewController1 by dragging it from the tools.
Tried to do the same thing in TableViewController2 and it won't drop the bar button.
I have the "Shows Navigation Bar" attribute checked on the Navigation Controller and I can see a space for the navigation bar on TableViewController2, but I don't see the same "Navigation Item" in the component hierarchy that I see for TableViewController1.
If I drag a bar button to the controller itself it puts a new NavigationItem icon on the controller (between First Responder and Exit) and that looks promising, but it doesn't show when I run the app.
For this TableViewController2, you have to explicitly add a navigation item into the xib and then you can add bar button items on it.
It will look like this in xib , you can set title and button.

Resources