Search code examples
iosswiftuinavigationcontrolleruinavigationbaruistoryboard

Add a right button to a nested view in a UINavigation stacking using Storyboards


Lets say we have a UIViewController embedded in a UINavigationController, the UIViewController segue to another UIViewController.

The second UIViewController has the standard left navigation button that "unwinds" to the previous UIViewController.

I don't seem to be able to add a righthand button (using a UIBarButtonItem) to the navigation bar of the second UIViewController via the Storyboard, when I attempt this the button ends up creating a tab bar at the bottom of the UIViewController (see below, notice also the left buttons are missing). Is there some trick I am missing? enter image description here

I could embedded the second UIViewController in its own UINavigationController but then I loss the back button functionality.

I know it is possible to add the button in code so all is not lost if I am attempting something that isint possible.


Solution

  • To do this in the Storyboard, you need to place a UINavigationItem onto your UIViewController. Then you can add your UIBarButtonItem(s).