在 UIViewController 中添加导航项 [英] Adding Navigation Item in UIViewController

查看:32
本文介绍了在 UIViewController 中添加导航项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 UINavigationItem 添加到我的 UIViewController 中 这个答案.但是导航栏没有显示在我的视图中.我什至尝试添加一个插座并以编程方式设置标题,并在两个不同的地方添加 NavigationItem.还是不显示.此视图控制器嵌入在 TabBarController 中.我在这里错过了什么?

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?

先谢谢了.

推荐答案

此视图控制器嵌入在 TabBarController 中

This view controller is embedded in a TabBarController

但它是否首先嵌入在 UINavigationController 中?如果没有,将不会自动出现导航栏并自动使用您的视图控制器的导航项.

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.

如果您不想使用 UINavigationController(因为您没有导航可做),那么您可以手动添加导航栏.但在这种情况下,您的视图控制器的导航项将不会自动用于填充导航栏;您必须手动填充它.

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.

通常,人们确实使用 UINavigationController,即使没有导航要做,只是为了获得这种自动行为 - 显示导航栏并自动填充它.

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.

[注意:您已经告诉 Interface Builder 显示这个视图控制器的导航栏,就好像它在导航控制器中,这一事实是无关紧要的;这不会导致您在应用程序运行时看到任何导航栏.]

[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.]

这篇关于在 UIViewController 中添加导航项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆