简体   繁体   中英

Cannot add right bar button in navigation bar in storyboards iOS8

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

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.

如果要将BarButtonItem添加到非RootViewController,则必须先将Navigation Item添加到ViewController。

First select a UIBarButtonItem from the object library. Then drag into the right corner of the navigationBar.

的UIBarButtonItem导航栏

I had a similar problem.

Try changing your Views simulated size to Freeform. The property is found under Size Inspector.

Another case in which I had problems adding a bar item to the top bar is if a Navigation Controller seques to a Tab Bar Controller. In that case you have to add the bar items to the TabV Bar Controller Navigation Item, not the individual View Controllers that are attached to the Tab Bar Controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM