Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add right bar button in navigation bar in storyboards iOS8

Tags:

As the title suggests, I would like to know if it is possible to avoid adding right bar button in the navigation bar through code.

I've done the usual process with a view controller embedded in a navigation controller and trying to drop the bar button item inside the navigation bar of the view controller, but it no longer works for some reasons.

So is it possible to be done in the storyboard somehow in iOS 8?

Xcode ver. 6.2 Stable

like image 778
Fawkes Avatar asked Mar 25 '15 16:03

Fawkes


People also ask

How do I add a navigation bar in Xcode storyboard?

Go to the Storyboard. Select the View Controller and in The Editor menu select Embed in -> Navigation Controller. Next, drag a Bar Button from the Object Library to the left side of the Navigation Bar and name it "Left Item". Repeat this for the right side and name it "Right Item".

How do I add a navigation controller to my storyboard?

Under the View menu, select Utilities→Show Object Library. In the Object Library, find the Navigation Controller object (see Figure 4-7) and drag and drop it into the storyboard, to the left side of your existing view controller (Figure 4-6).


2 Answers

Well, it seems there is a problem with the differences between new segues introduced in iOS 8 and the old ones. In this case it is the difference between push segues which allows adding a right bar button in storyboard and show segue which if added automatically (dragging from a controller to another) does not allow dropping the button in the navigation bar.

The reason is when using the old segues, the controller would automatically be given a navigation bar, thus you can add elements to it, while if using the new segues the navigation bar is not automatically added to the controller in the storyboard.

What solved this issue for me was:

  1. Selecting the segue which leads to the problematic controller
  2. Changing it to the "deprecated" push segue
  3. Changing it back to the accepted show segue

Result: Now I can add as always the right bar button item through Storyboard.

like image 84
Fawkes Avatar answered Oct 15 '22 07:10

Fawkes


if you want to add BarButtonItem to not RootViewController you must first add Navigation Item to your ViewController.

like image 39
Tomasz Rejdych Avatar answered Oct 15 '22 08:10

Tomasz Rejdych