Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 330
user1904273 Avatar asked Apr 03 '15 16:04

user1904273


People also ask

How do you attach a button to a storyboard?

To connect a button to an action, hold down control while clicking and dragging from the button to the action you want to attach it to. Thank you so much for the advice!

How do I link a button to Storyboard in Xcode?

Hold the control and click-drag from the storyboard button into your view controller source file as if you were to create a IBOutlet. When prompted to name your IBOutlet, change the connection type from Outlet to Action using the dropdown menu.

How do I use the navigation bar in Xcode?

To add a navigation bar to your interface, the following steps are required: Set up Auto Layout rules to govern the position of the navigation bar in your interface. Create a root navigation item to supply the initial title. Configure a delegate object to handle user interactions with the navigation bar.


2 Answers

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

like image 79
Wael Showair Avatar answered Oct 15 '22 16:10

Wael Showair


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.

like image 29
Baxter Lopez Avatar answered Oct 15 '22 16:10

Baxter Lopez