2

I hope anyone can explane me how to do this:

I have a TabBar and two TabBarItems, how can I attatch the Items to the TabBar. I am not doing this via IB because the TabBar only fits have of the screen because the items should be on the left side.

thats how i build them:

tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBarController2 = [[UITabBarController alloc] initWithNibName:nil bundle:nil];

tabBarController.tabBar.frame = CGRectMake(0, 974, 384, 50);    
tabBarController2.tabBar.frame = CGRectMake(384, 974, 384, 50);

UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
UITabBarItem *tbi2 = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
Frank
  • 155
  • 3
  • 13

1 Answers1

6

You don't set tab bar items directly in the tab bar. Instead, you assign a tab bar item to the tabBarItem property for each view controller contained by your tab bar controller. Then when you add your view controllers to the tab bar controller, the tab bar controller will manage the display of your tab bar items for you.

UITabBarController * tabBarController = [[UITabBarController alloc] init];

UIViewController * viewController1 = [[YourViewController alloc] init];
UIViewController * viewController2 = [[YourOtherViewController alloc] init];

viewController1.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
viewController2.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];

tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
Ryan
  • 16,626
  • 2
  • 23
  • 20
  • I already tried that but it did not worked out for me but that was caused by my second TabBar. – Frank Dec 01 '10 at 18:04
  • the fault was taht i tought that when i shrink the tabbar it only effects the tabbar. now i cheated i filled one side with blank buttons and disabled them and now i have my seperated tabbar..... – Frank Dec 04 '10 at 13:56