2

I have a UINavigationController in Interface Builder in a storyboard. I've added two UIBarButtonItems to the first UIViewController. They display just fine. How can I add them to the second UIViewController which is navigatated to? On that view controller, I only see the Back button.

When I try dragging a UIBarButtonItem to the top of the second view controller, the button ends up at the bottom of the scene for some reason. It is not displayed when running the app.

Edit: I should have mentioned that I know how to do this in code, but not in Interface Builder.

Adding UIBarButtonItems in Interface Builder

royco
  • 5,409
  • 13
  • 60
  • 84
  • check http://stackoverflow.com/a/14329962/3633534 – Sujay Feb 25 '16 at 07:31
  • Possible duplicate of [How to add multiple UIBarButtonItems on right side of Navigation Bar?](http://stackoverflow.com/questions/30341263/how-to-add-multiple-uibarbuttonitems-on-right-side-of-navigation-bar) – Sujay Feb 25 '16 at 07:32
  • 1
    Did you drag and drop an Navigation item in the second view controller from interface builder ? – Michaël Azevedo Feb 25 '16 at 07:36
  • @Sujay Any idea how to do it in IB instead of code? – royco Feb 25 '16 at 07:42
  • @MichaëlAzevedo the second view controller has nothing special added to it. I just created a segue from the button to the second view controller and then tried adding UIBarButtonItems to the space at the top. Did I miss a step? – royco Feb 25 '16 at 07:43
  • @Slack, Just drag and drop 2 "bar button item' in your navigation bar. – Sujay Feb 25 '16 at 07:49

2 Answers2

3

To add further informations about my comments concerning navigation item :

Here is a simple project with a UIViewController embedded in a UINavigationController. A second UIViewControllercan be pushed via the Next button. If you select the next button, you can see in the hierarchy that this button is embedded within the group Right Bar Buttons Items, which is embedded within the First object. In fact, First is a UINavigationItem automatically added to your view controller when it was embedded in the navigation controller.

enter image description here

But the second view controller (the pushed one) doesn't have this navigation item since it isn't directly embedded within a navigation controller. Simply drag and drop it from the Object Library to your view controller.

enter image description here

Michaël Azevedo
  • 3,874
  • 7
  • 31
  • 45
  • 1
    Thanks, this was it. In summary: adding a second view controller in IB does not include a Navigation Item. Just drag that onto the second view controller, and then UIBarButtonItems can be placed on top of it. – royco Feb 25 '16 at 18:13
2

@Slack, As i said earlier just drag and drop 2 "bar button item" in your navigation bar.

enter image description here

Sujay
  • 2,510
  • 2
  • 27
  • 47
  • You can do it in the view controller directly embedded within the navigation controller, but if you add a view controller after this one, you add to manually add the navigation item first. – Michaël Azevedo Feb 25 '16 at 08:27
  • @MichaëlAzevedo- No, I haven't added navigation item. Directly dragged and dropped bar button item in navigation bar – Sujay Feb 25 '16 at 09:03
  • @Sujay: This works for the root view controller, but if you add a 2nd view controller, it does not contain a navigation item. Maybe my original question wasn't clear enough. Thanks for thinking about it though. – royco Feb 25 '16 at 18:25