bar button in Xcode always goes to bottom Xcode 6.3 beta - ios

when i drag the bar button item onto the view controller they will not stay at the top of the view they will automatically go to the bottom under the table view. Does anyone know what is wrong?

You can fix this by moving the bar button item under the navigation item, inside document outline windows.
Before
After
That should fix the issue. I verified the issue in Xcode 6.3.2

If you navigated to this view-controller via a push segue, it does not have an instance of the navigation bar in storyboard.
You need to drag in a "Navigation Item" object, and then you can add your Bar Button Item on to this.

indy and timbrah's fixes didn't work for me... but the below did.
To fix this, select Navigation Item in the Object Library and drag it onto the Root View. Note, it replaces the current one. Then you can drag a Bar Button Item onto as you like. Hope this helps.

Actually, it seems as if the top bar isn't clearly designated as a navigation bar anymore. I had to select Root View Controller (first icon at the very top left of the screen) then chose the Show Attributes Inspector and at the Top Bar line item under Simulated Metrics chose Translucent Navigation Bar. That enabled it as a navigation bar and I was abled to drag a bar button item there. Weird!

I had same issue today with XCode 7. I have next stack: NC-(root)->VC1-(Show (e.g. Push))->VC2. After I've created VC2 there was no Navigation Item at all. To make it appear I changed segue type from Show (e.g. Push) to Deprecated Push and brought it back to Show (e.g. Push) and now I can use it correctly

You have to drag the Bar Button Item to one of the sides of the navigation controller's navigation bar. So, in your screenshot it would be all the way to the right or left of that bar that has "Root View Controller" in it.

From what I can tell this bug is still around in the 6.3 release. The only way I've been able to add items when this happens is to drag them under the navigation item in the left hand sidebar.

In my situation needed to select ViewControllerScene inside the document outline then forward attributes inspector then change Top Bar to Translucent Navigation Bar

Related

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/storyboard: can't drag bar button to toolbar at top

I have a view controller that is the detail view of a table. When you click on the row of the table it takes you to the detail view. The detail view is embedded in a navigation controller such that there is a button at the upper left of the navigation bar that sends you back to the table. So far so good.
I now want to add an edit button to the right side of the navigation bar so that you can edit the detail view. My plan is this will add another view controller modally that lets you edit the details of the item. Standard stuff.
However, when I try to drag a bar button item from the list of objects to the navigation bar, it won't take. Instead, when I let go off the mouse button, it leaves the bar button on the tab bar controller at the bottom. (My navigation scheme includes different tabs and for each tab a table, detail view etc.)
Anyone run across this before and can suggest what I'm doing wrong or some sort of workaround to add the bar button item to the right side of the navigation screen. Do I have to add it in code?
Thanks for any suggestions.
I have got the same problem using Xcode6 and I noticed that UINavigationItem is added automatically for the first ViewController that you embed into NavigationController but for the subsequent ViewControllers, you will have to add it manually as follows:
In the Object library, find Navigation Item then drag it to your
2nd ViewController in the storyboard.
In the Object library, find
Bar Button Item then drag it the navigation item that you have created in the previous step.
Now you will have your Bar Buttons stuck to the top of your scene.
Update
The solution still works with XCode 7 but I wanted to add more descriptive photo. Just in case anyone is not really familiar with standard or technical names mentioned above. Notice the red arrows in the right, they refer to step 1, step 2 mentioned above. Also note the hierarchy of views on the left red rectangle.
Nasty trick:
Change your segue to push.
Set the content you need
Set back to show
Then the content will be editable and you have a non deprecated style for segue.
Your storyboard's view controller is likely missing a Navigation Item. You can drag one from the Object library, and drop it on your view controller.
You'll then be able to drag and drop bar button items onto the left or right side of the navigation bar.
i Solved it. drag in 'Navigation Item' to your detail view. than you can drag in the Bar Button Item.
The way that I fixed this issue was, instead of dragging a UINavigationController into the Storyboard and trying to add UIBarButtonItems to that, I dragged in a UITableViewController and then went to
Editor->Embed In->Navigation Controller
Which gave the same result as before except I could add UIBarButtonItems to both sides of the navigation bar with no issues.
Its actually xcode issue.
One trick which worked for me is to add the bar button in the VIEW FILE STRUCTURE ON THE LEFT.Instaed adding on the view directly.
Hope it helps you.:)
I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.
You can disable and enable the size classes in Interface builder doc.
I also had this problem, close and reopen the project worked for me.
I believe it's an XCode quirk. I had the same issue. I had to reset Xcode and shift the placement of things on the storyboard to finally get it to go. It's working now.
I think this is a bug of Xcode. In Xcode 8, change the segue in storyboard before the tab bar view controller to all its options (show detail, present...). Then back to show. Try to drag bar button items and modify tile. It works for me!
Did you try "cleaning" your project? I know that helps me sometimes (just go to "Product" > "Clean"). Or, alternatively, delete the navigation bar and try it again.
If you think it's a programming error, feel free to pass on your code. I'd be happy to help in any way I can. :)
You must reset xCode IDE . Close xCode and write the below codes at terminal...It will work.
rm -rf $HOME/Library/Application Support/Developer/Shared/Xcode
rm -rf $HOME/Library/Preferences/com.apple.dt.Xcode.*
rm -rf $HOME/Library/Saved\ Application\ State/com.apple.dt.Xcode.savedState
rm -rf $HOME/Library/Developer/Xcode
Same issue. I had a Table View Controller inside a Navigation Controller and many ViewControllers following further down the chain. A 'Navigation Item' was being created automatically for the FIRST root view controller and I could add a 'Bar Button Item' to this without a problem. Via the Storyboard, drag and drop. But thats all. On the following Table View Controller and further view controllers, even though they were within the initial Navigation Controller (auto generated back button appeared), storyboard would never let me add a Bar Button Item.
Wael Showair's solution did not work for me. Bar Button Items wouldn't appear.
I solved it programmatically in the end (Swift 2.0):
var testButton = UIBarButtonItem(title: "Test Button", style .Plain, target: self, action: "testButtonMethod")
self.tabBarController?.navigationItem.rightBarButtonItem = testButton
No extra Navigation item or Bar Button Item needed.
I was too facing the same problem.I was able to fix this issue by selecting the root view controller option and then in simulated matrix changed the Top bar option to Opaque Navigation Bar and was able to add the item on top of navigation bar.Hope this answer will help someone.
I had the same issue in xcode 8. I had to simply close xcode and reopen the project and then I was able to add the bar button to the Root Controller without any issues.
For XCode 8
There are many answers here. I tried some of them but I couldn't make it.
So I found my solution, just select your ViewController, go Attributes Inspector section and change the Top Bar to Opaque Navigation Bar and Boom. You will see navigation bar on your storyboard. You can change the title or add some item. If you don't want to keep Opaque you can change style to Inferred.
In Xcode 10, I just changed the type of segue going to this new view controller to 'Push (deprecated)', added the navigation item as it was allowed after I made this switch. If you switch back to your originally desired segue type, the navigation item will remain.
Instead of drag the "Bar Button Item" to the "Navigation Controller", drag it to the "Detail View Controller".
As you embed the Detail view into the "Navigation View", "Navigation Item" will be added to the "Detail View Controller". If you drag the "Bar Button Item" to the right side of the Navigation Item, the item will be included under the "Right Bar Button Items"
like Mark Lyons said , I used the same solution.
used push segue first
added the bar item
return back to show segue
done
In Xcode 11, you can drag a button to the navigation bar to create your bar button.

How to add buttons to navigation controller visible after segueing?

I have set up a view controller in Storyboard which is embedded in a navigation controller. In this nav controller I have checked Shows Navigation Bar and Shows Toolbar and enabled a navigation bar and toolbar in Top Bar and Bottom Bar respectively in Simulated Metrics. I then "Show e.g. Push" segue from the view controller to another view controller. On both view controllers I've set up Simulated Metrics the same way, so both the navigation bar and toolbar are visible on all three controllers.
The problem is, I can add bar button items to the first view controller to both the navigation bar and the toolbar, but I cannot add a bar button item to the navigation bar on the second view controller. When I drop a button on the navigation bar, it's added to the toolbar instead. And I cannot double click the nav bar to add a title. In the outline I see there is no navigation item on the second view controller, but it is there in the first view controller.
I can probably add buttons to the navigation bar programmatically, but I want to do this visually in Storyboard. My question is, what is wrong with this setup, or is this a bug with Xcode?
For XCode 6, the UINavigationItem for the 2nd view controller onwards is not added automatically on the View Controller Object inside the storyboard. You will have to drag the UINavigationItem onto the Navigation Bar for that view Controller Object before adding UIBarButtonItem on top of it.
I am not sure why it is designed that way. I only discovered about this a few weeks ago.
If you have a ton of view controllers and very little custom auto-layout stuff in place, you can disable size classes, then re-enable it will add all missing nav bars across your storyboard.
Obviously not recommended if you have a ton of custom auto layout stuff linked up.
If you have just a single UIViewController that's missing a nav bar, just drop a UINavigationItem onto it.
If you're using Xcode 7 beta 4/5, try restarting Xcode it solved the issue for me
I just bumped into this issue and it seems to be affected by the segue that shows the view controller.
If "Kind" setting in segue is "Show (e.g. Push)", it's not possible to drag the item to top right corner. However, if you explicitly change "Kind" setting to "Push", this can be done.
Edit: actually I just noticed that "Push" is deprecated. Not sure what Apple is thinking here. However, you can just change it back to "Show" after adding the button and it seems to work :D
For second view controller in hierarchy, you can setup title in attributes, without adding "navigation item"
I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.
You can disable and enable the size classes in Interface builder doc.
It's very simple. You just need to use navigaitonItem first as the holder of the buttons and then you can add barButtonItems on top of that.

Xcode Storyboard issue - Button Bar Button only appears at the bottom of a TableViewController

Not sure if this is a bug in Xcode 6(I use Beta 4) or expected behaviour.
When I have a View Controller in a Navigation Controller and 'push' (deprecated segue) a Table View Controller(TVC) I can drag a Bar Button Item to the Navigation Bar in the TVC.
When I do the same but 'show' (new adaptive segue) the TVC, the Bar Button Item drops to the bottom, and in fact doesn't show up when I build the project.
A hack to resolve this problem is to set it up as 'Push' to begin with, drag on the Bar Button Item, and then change the segue to 'Show'. But - is this necessary? Is this an Xcode Bug or am I missing something?
I have tried creating the issue you are facing with bar button at bottom. It’s not an issue or Xcode bug.
But in new Xcode when you use segue to ’Show (e.g. Push)’ then in next view you won’t get navigation bar.
You need to add navigation bar and then add bar button item to navigation bar.
Hope your problem will be solved.
I had the same issue and fixed it by simply selecting the view controller and changing the "Top Bar" to "Opaque Navigation Bar" from Inferred. This let me add the Bar Button Item on top.

Resources