Yuting
Yuting

Reputation: 131

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.

Upvotes: 2

Views: 1473

Answers (2)

Yuting
Yuting

Reputation: 131

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.

Upvotes: 2

rdelmar
rdelmar

Reputation: 104092

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.

Upvotes: 1

Related Questions