标题未出现在 TabBarItem 中,但图像出现
我添加了一个选项卡栏控制器,并尝试向该项目添加标题和图像,但仅显示图像。标题根本就看不到。任何建议将不胜感激。
_tabbarController = [[UITabBarController alloc] init];
_showsController = [[showsController alloc] init];
_showsController.title = @"Test1";
_showsController.tabBarItem.image = [UIImage imageNamed:@"Glass.png"];
[_tabbarController setViewControllers: [NSArray arrayWithObjects: _showsController, nil]];
更新: 在stackoverflow上搜索了一段时间,终于找到了解决办法,添加如下代码: *self.view = _tabbarController.view;*
我很抱歉没有提供更多信息(这不是 rootViewController,而是作为子视图添加的),并感谢您的帮助。
I've added a tab bar controller and am trying to add a title and image to the item, but only the image shows. The title is nowhere to be seen. Any suggestions would be greatly appreciated.
_tabbarController = [[UITabBarController alloc] init];
_showsController = [[showsController alloc] init];
_showsController.title = @"Test1";
_showsController.tabBarItem.image = [UIImage imageNamed:@"Glass.png"];
[_tabbarController setViewControllers: [NSArray arrayWithObjects: _showsController, nil]];
UPDATE:
After searching stackoverflow for a while, I finally found the solution by adding the following code:
*self.view = _tabbarController.view;*
I apologize for not giving more information (that this was not the rootViewController but added as a subview instead), and thank you for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要设置
UITabBarItem
标题:或者一次性设置它们:
You need to set the
UITabBarItem
title:Or set them both in one go:
您还需要在
UITabBarItem
对象上设置标题。就我个人而言,我更喜欢让 UIViewController 子类在可能的情况下处理自己的标题。这使您的代码更加独立,并且并不总是强制 UIViewController 的创建者正确初始化它。
例如,在您的 UIViewController 子类中:
You also need to set the title on the
UITabBarItem
object.Personally, I prefer to let the UIViewController subclass handle its own titles when possible. This makes your code more self-contained and doesn't always force the UIViewController's creator to initialize it properly.
For example, in your UIViewController subclass: