我无法以编程方式为我的标签栏控制器设置标题 [英] I can not set title to my programatically tab bar controller

查看:32
本文介绍了我无法以编程方式为我的标签栏控制器设置标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以编程方式创建标签栏控制器.没关系,但我无法为标签栏项目设置标题.. 我该怎么做?

I try to create tab bar controller as programatically. It is ok but I can not set title to tab bar items.. How can I do this?

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

myTabBarController = [[UITabBarController alloc] init];        
tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil];   
tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil];   
tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil];  
tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];    
tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil];  

UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"title" image:nil tag:0];
tab1.tabBarItem = item;

myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1, tab2,tab3,tab4,tab5,nil]; 


[self.view addSubview:myTabBarController.view];    
myTabBarController.selectedIndex=0;

}

推荐答案

UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];

此行中的

1 表示,您尝试从数组中获取 second 对象.

1 in this line means, that you try to get second object from array.

UITabBarItem 也有很好的方法 initWithTitle:image:tag:.而 this 是文档的链接它非常有帮助.

Also UITabBarItem has nice method initWithTitle:image:tag:. And this is link to documenttion its very helpfull.

我的解决办法:

1) 创建一些项目:

initWithTitle:image:tag:

2) 使用标签栏方法将它们添加到您的标签栏:

2) Add them to your tabbar with tab bar method:

- (void)setItems:(NSArray *)items animated:(BOOL)animated

这篇关于我无法以编程方式为我的标签栏控制器设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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