xcode/storyboard: can't drag bar button to toolbar at top

IosXcodeNavigationUibarbuttonitem

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

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:

  1. In the Object library, find Navigation Item then drag it to your 2nd ViewController in the storyboard.
  2. 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. enter image description here

Solution 2 - Ios

Nasty trick:

  1. Change your segue to push.
  2. Set the content you need
  3. Set back to show

Then the content will be editable and you have a non deprecated style for segue.

Solution 3 - Ios

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.

Solution 4 - Ios

i Solved it. drag in 'Navigation Item' to your detail view. than you can drag in the Bar Button Item.

Solution 5 - Ios

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.

Solution 6 - Ios

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.:)

Solution 7 - Ios

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.

enter image description here

Solution 8 - Ios

I also had this problem, close and reopen the project worked for me.

Solution 9 - Ios

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.

Solution 10 - Ios

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!

Solution 11 - Ios

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. :)

Solution 12 - Ios

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

Solution 13 - Ios

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.

Solution 14 - Ios

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.

Solution 15 - Ios

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.

Solution 16 - Ios

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.

enter image description here

Solution 17 - Ios

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.

Solution 18 - Ios

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"

Solution 19 - Ios

like Mark Lyons said , I used the same solution.

  • used push segue first
  • added the bar item
  • return back to show segue
  • done

Solution 20 - Ios

In Xcode 11, you can drag a button to the navigation bar to create your bar button.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1904273View Question on Stackoverflow
Solution 1 - IosWael ShowairView Answer on Stackoverflow
Solution 2 - IosBaxter LopezView Answer on Stackoverflow
Solution 3 - Iosuser4151918View Answer on Stackoverflow
Solution 4 - IosJamal N. AhmadView Answer on Stackoverflow
Solution 5 - Iostallen11View Answer on Stackoverflow
Solution 6 - IosChetan KumarView Answer on Stackoverflow
Solution 7 - IosHongyangView Answer on Stackoverflow
Solution 8 - IosHsmView Answer on Stackoverflow
Solution 9 - IosrotarycuffView Answer on Stackoverflow
Solution 10 - IosDanView Answer on Stackoverflow
Solution 11 - IosJJ YuView Answer on Stackoverflow
Solution 12 - IosYusuf KıldanView Answer on Stackoverflow
Solution 13 - IosElliott DaviesView Answer on Stackoverflow
Solution 14 - IosreetuView Answer on Stackoverflow
Solution 15 - IosSGMView Answer on Stackoverflow
Solution 16 - IosemresancaktarView Answer on Stackoverflow
Solution 17 - IosMark LyonsView Answer on Stackoverflow
Solution 18 - IosNancyView Answer on Stackoverflow
Solution 19 - IosA_MoView Answer on Stackoverflow
Solution 20 - IosSalaView Answer on Stackoverflow