选项卡栏项目标题以编程方式不显示在目标 c 中
我尝试以编程方式创建选项卡栏控制器,它可以工作,但我无法将标题设置为选项卡栏项目。运行应用程序时我看不到标题。我的代码在这里。请帮帮我,有什么问题吗?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
view2Controller = [[testView alloc] init];
view3Controller = [[testView2 alloc] init];
view4Controller = [[testView3 alloc] init];
view5Controller = [[testView4 alloc] init];
view6Controller = [[testView5 alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects: view2Controller, view3Controller,view4Controller,view5Controller,view6Controller,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:@"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
I try create tab bar controller programatically, it works but I can not set title to ta bar items. I can not see title when I running my application. My code is here. Please help me, what is the problem?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
view2Controller = [[testView alloc] init];
view3Controller = [[testView2 alloc] init];
view4Controller = [[testView3 alloc] init];
view5Controller = [[testView4 alloc] init];
view6Controller = [[testView5 alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects: view2Controller, view3Controller,view4Controller,view5Controller,view6Controller,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:@"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
设置 侧视图控制器的视图中的视图控制器的标题将会出现/消失,它将显示在您的选项卡项中。
Set the title of ur viewcontroller in side viewcontroller's viewwillappear/disappear and it will be displayed in ur tabbaritem.
您可以设置
UIViewController
的标题,该标题反映了它何时被推送到UINavigationController
或UITabBarController
中。但您应该先设置标题,然后再将其放入其中任何一个中。init
通常是设置标题的好地方。You can set the title of
UIViewController
, which reflects when it is pushed inUINavigationController
or aUITabBarController
. But you should set the title before putting it inside any of them.init
is generally a good place to set the title.在标签栏控制器的每个子视图中使用上面的代码。
这可能会有帮助。
Use above code in every subviews of tabbar controllers.
This may be help.
这里是从头开始的教程,应该可以帮助您实现您想要实现的确切功能。下载源代码并直接运行,如果标题正确,您可以按照教程正确理解 UITabBarController 的流程。
Here is the tutorial from the scratch which should help you to achieve the exact functionality you want to achieve. Download the source code and run it directly and if title are correct the you can follow the tutorial to get the proper understanding of the flow of UITabBarController.
或者
OR