UIViewController故事板中的标题属性 [英] UIViewController Title attribute in Storyboard

查看:113
本文介绍了UIViewController故事板中的标题属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 Interface Builder / Storyboard 设置 UIViewController 的标题字段:

I am setting the title field of a UIViewController via Interface Builder/Storyboard:

此视图控制器嵌套在 UINavigationController ,它又嵌套在 UITabBarController 中。当我运行应用程序,我的导航项没有标题,标签栏项目也没有。

This view controller is nested in a UINavigationController which in turn is nested within a UITabBarController. When I run the app, I my navigation item has no title, neither does the tab bar item.

如果我明确设置视图控制器的导航项目的标题,以及它的界面生成器中的标签栏项目的标题,那么它工作正常。

If I explicitly set the view controller's navigation item's title, and also it's tab bar item's title in interface builder, then it works just fine.

我想知道:

a)如果我不使用故事板,而只是常规 xibs ,设置视图控制器的标题隐含地设置导航项目的标题以及选项卡栏项目的标题。但它不一样的故事板。这是预期的行为吗?

a)If I am not using Storyboard but just regular xibs, setting the title of a view controller implicitly sets the navigation items' title as well as the tab bar item's title. But it's not the same storyboard. Is this the intended behaviour?

b)那么视图控制器标题的目的是什么(在故事板它似乎没有效果。

b) What is then the purpose of the view controller's title (in Storyboard)? it seems to have no effect.

谢谢!

推荐答案

可以通过双击实际的导航栏并在其中键入标题来设置故事板中的 UINavigationBar 的标题。这只会设置 UINavigationBar 的标题。

You can set the title of the UINavigationBar in Storyboard by double clicking the actual navigationBar and typing in a title right there. This only sets the title for the UINavigationBar.

在代码中设置标题提供了一些不同的可能性。

Setting the title in code offers some different possibilities.

self.title = @您的标题; 将设置导航栏的标题,

self.title = @"Your title"; will set the title of a navigationBar and also cause the title to cascade down to a UITabBarItem, if present.

self.navigationItem.title = @Your title; 将只设置一个UITabBarItem

self.navigationItem.title = @"Your title"; will only set the title of the navigationBar, assuming a UINavigationController is present, and NOT affect a UITabBarItem.

self.navigationController.title = @您的标题是一个标题,即navigationBar的标题,假设一个UINavigationController存在,并且不影响UITabBarItem。 ; 将设置UITabBarItem的标题,但不是UINavigationBar。

self.navigationController.title = @"Your title"; will set the title of a UITabBarItem but NOT the UINavigationBar.

这篇关于UIViewController故事板中的标题属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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