I can not set title to my programatically tab bar controller

空扰寡人 提交于 2020-01-16 08:55:50

问题


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;

}

回答1:


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

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

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

My solve:

1) Create some items with:

initWithTitle:image:tag:

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

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


来源:https://stackoverflow.com/questions/9044331/i-can-not-set-title-to-my-programatically-tab-bar-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!