问题
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