How to add buttons to navigation controller visible after segueing?

試著忘記壹切 提交于 2019-11-27 17:42:09

For XCode 6, the UINavigationItem for the 2nd view controller onwards is not added automatically on the View Controller Object inside the storyboard. You will have to drag the UINavigationItem onto the Navigation Bar for that view Controller Object before adding UIBarButtonItem on top of it.

I am not sure why it is designed that way. I only discovered about this a few weeks ago.

If you have a ton of view controllers and very little custom auto-layout stuff in place, you can disable size classes, then re-enable it will add all missing nav bars across your storyboard.

Obviously not recommended if you have a ton of custom auto layout stuff linked up.

If you have just a single UIViewController that's missing a nav bar, just drop a UINavigationItem onto it.

If you're using Xcode 7 beta 4/5, try restarting Xcode it solved the issue for me

I just bumped into this issue and it seems to be affected by the segue that shows the view controller.

If "Kind" setting in segue is "Show (e.g. Push)", it's not possible to drag the item to top right corner. However, if you explicitly change "Kind" setting to "Push", this can be done.

Edit: actually I just noticed that "Push" is deprecated. Not sure what Apple is thinking here. However, you can just change it back to "Show" after adding the button and it seems to work :D

For second view controller in hierarchy, you can setup title in attributes, without adding "navigation item"

Hongyang

I think it is a bug. I had the same problem.I fixed this problem by disable the size classes, then enable it.

You can disable and enable the size classes in Interface builder doc.

It's very simple. You just need to use navigaitonItem first as the holder of the buttons and then you can add barButtonItems on top of that.

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