Cannot add right bar button in navigation bar in storyboards iOS8

℡╲_俬逩灬. 提交于 2019-12-09 04:32:42

问题


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


回答1:


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.




回答2:


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




回答3:


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




回答4:


I had a similar problem.

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




回答5:


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.



来源:https://stackoverflow.com/questions/29261134/cannot-add-right-bar-button-in-navigation-bar-in-storyboards-ios8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!