Question

I drag out a toolbaritem in storyboard and set it on my nav controller, but when I run my code it's not there, is there something I'm missing?

EDIT:

Tried setting it in code as well in my viewDidLoad method:

UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Map" style:UIBarButtonItemStyleBordered target:self action:@selector(viewMap)];
self.navigationItem.rightBarButtonItem = rightBarButton;

Won't work either.

Here's how it's set up in my storyboard:

enter image description here

UPDATE:

Just found my problem. In my controller code when I update it's contents I change the right bar button item for a spinner and never set it back to what it had before.

Was it helpful?

Solution

UINavigationController already has a toolbar built in. It has a property toolBarHidden which is set to YES by default, which is why it is not normally seen. If you are using storyboard you can easily make the built-in bottom toolbar visible by checking the checkbox "Shows Toolbar" in the inspector when the Navigation Controller is selected.

See the UINavigationController documentation here for more details.

EDIT:

Ok, it sounds like what you are trying to do is add a right button to your view controller's UINavigationItem. To do this in storyboard, drag a "Bar Button Item" from the Objects Library onto the Navigation Item in your ViewController. You can then set the title/style/etc of the bar button item. If nothing still shows up when you run your app, make sure that your ViewController is connected properly with a segue to the navigation controller.

Also make sure you are adding the Bar Button Item to your view controller's Navigation Item, NOT to the View Controller itself. Here is how the setup should look in your storyboard:

enter image description here

OTHER TIPS

To add an item to a navigation bar, you need to add a Bar Button Item to the Navigation Item contained in the view controller. Go to your storyboard, find the right VC, and find the navigation item (it's in the hierarchy shown in the navigation controller 'scene'). Just drag a Bar Button Item into that hierarchy underneath the nav item, or directly onto the navbar in the visual builder display.

The navigation controller only looks at your VC's nav item when that VC is pushed onto the stack; hence modifying the VC's nav item in viewDidLoad has no effect.

(I've done this programmatically before but I don't have the code with me, so maybe I'll add that later...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top