How to add UIToolbar to NavigationController on storyboard?

I am not a big fan of using Interface Builder and for this reason I am new to this.

I am trying to add a UIToolbar to the navigation controller, but since Apple's documentation is always very clear, I have no hint.

I am using an old project to use storyboards.

This is what I did.

  • I added a storyboard to the project
  • I added a navigation controller to it
  • Since I want this navigation controller to display the toolbar at the bottom, I clicked on the navigation controller and turned on the toolbar (see figure).

enter image description here

after that, a white rectangle appeared on the bottom of the navigation controller on the interface builder. I think this is a UIToolBar or placeholder. I tried to drag the BarButtonItem into this “space” and enable Xcode, showing it like this:

enter image description here

When I launch the application, the toolbar appears as a white rectangle at the bottom, not a button.

The button is displayed in the hierarchy as follows:

enter image description here

I suppose the button should be inside the toolbar item, but Xcode prevents the item from being dragged there.

How do I show a button?

+7
ios cocoa-touch uistoryboard uinavigationcontroller uitoolbar
source share
2 answers

The problem is that you are trying to add a UIToolBar to the UINavigationController ...

Try it in the UIViewController and it will work!

Edit:

enter image description hereenter image description here

+2
source share

Try the following:

You just drag and drop the UINavigationItem into the UINavigation RootViewController instead of the UIToolbar.

This will allow you to put the UIBarButtonItem in this UINavigationItem and work just like the UIToolbar Button.

+2
source share

All Articles