Adding Navigation Item in UIViewController

时光怂恿深爱的人放手 提交于 2020-01-06 19:05:12

问题


I'm trying to add UINavigationItem to my UIViewController as mentioned this answer. However the Navigation bar is not showing in my view. I tried even adding an outlet and setting the title programmatically and also adding the NavigationItem in two different places. Still it doesn't show. This view controller is embedded in a TabBarController. WHat am I missing here?

Thanks is advance.


回答1:


This view controller is embedded in a TabBarController

But is it embedded, first and foremost, in a UINavigationController? If not, there will be no navigation bar that automatically appears and that automatically uses your view controller's navigation item.

If you don't want to use a UINavigationController (because you have no navigation to do), then you can add a navigation bar manually. But in that case your view controller's navigation item will not be used automatically to populate the navigation bar; you must populate it manually.

Typically, people do use a UINavigationController, even if there is no navigation to do, just to get this automatic behavior - to show the navigation bar and to populate it automatically.

[NOTE: The fact that you have told Interface Builder to show a navigation bar for this view controller, as if it were in a navigation controller, is irrelevant; that won't cause you to get any navigation bar when the app runs.]



来源:https://stackoverflow.com/questions/29997521/adding-navigation-item-in-uiviewcontroller

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