我无法为我的编程标签栏控制器设置标题

时间:2012-01-28 09:49:05

标签: objective-c ios uitabbarcontroller uitabbaritem

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

- (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;

}

1 个答案:

答案 0 :(得分:0)

UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
此行中的

1表示您尝试从数组中获取第二个对象。

UITabBarItem也有很好的方法initWithTitle:image:tag:this与文档链接非常有用。

我的解决方案:

1)创建一些项目:

initWithTitle:image:tag:

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

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