UITabBarItem 标题未显示

发布于 2024-10-30 09:28:46 字数 681 浏览 1 评论 0原文

我有一个 UITabBarController,其中第一个 UITabBarItem 标题未显示。我在 Interface Builder 中设置了它,并尝试以编程方式设置它,但标题区域保持空白。

[[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"Test1"];
[[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"Test2"];

UITabController view

(第 2 项是通过 Interface Builder 设置的,这是该标题的来源,只是为了测试IB 标题也可以工作——除了第一个)

我有一种感觉,这是将 UITabController 添加到项目并将现有视图拖到第一个位置的奇怪结果,但不知道如何修复它。

这是 Interface Builder 中的视图: 在此处输入图像描述

将第一个位置的 ViewController 移动到第二个位置会产生您期望的结果 -第二个位置变为空白,第一个位置设置为“Test1”,这意味着仅第一个位置并不有趣。

I have a UITabBarController in which the first UITabBarItem title is not getting displayed. I have it set in Interface Builder and have tried to set it programmatically, but the title area stays blank.

[[tabBarController.tabBar.items objectAtIndex:0] setTitle:@"Test1"];
[[tabBarController.tabBar.items objectAtIndex:1] setTitle:@"Test2"];

UITabController view

(The Item 2 is set through Interface Builder, which is where that title is coming from, just to test that the IB titles are working as well -- except for the first one)

I have a feeling this is the odd result of adding the UITabController to the project and dragging the existing view into the first spot, but don't know how to fix it.

Here's the view in Interface Builder:
enter image description here

Moving the ViewController that's in the first spot to the second spot yields the result you'd expect -- the second spot becomes blank and the first gets set with "Test1", meaning it's not something funny with just the first spot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甚是思念 2024-11-06 09:28:46

只需转到视图控制器的 .m 文件中的 init 方法,然后为了设置选项卡栏项目的标题,请使用:

[[self tabBarItem] setTitle:@"Main"];

并设置其图像,请使用:

[[self tabBarItem] setImage:[UIImage imageNamed:@"SomeFilename.png"]];

Just go to your init method in your view controller's .m file and in order to set the tab bar item's title use:

[[self tabBarItem] setTitle:@"Main"];

and for setting its image, use:

[[self tabBarItem] setImage:[UIImage imageNamed:@"SomeFilename.png"]];
一生独一 2024-11-06 09:28:46

在第一个视图的视图控制器中输入 [self setTitle:@"Title"] ,而不是通过视图控制器数组声明它。虽然不知道出了什么问题,但我不得不这样做一次

type [self setTitle:@"Title"] in your viewcontroller for the first view instead of declaring it through the viewcontrollers array. don't know whats wrong though, but I had to do this once

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文