views:

194

answers:

1

I created a UITabBarController like this:

InfoViewController *iVC = [[InfoViewController alloc] init];
self.infoViewController = iVC; // retain property

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
self.infoViewController.tabBarItem = tabBarItem;





UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:myVC];
self.navigationController = nc;

UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostRecent tag:1];
self.navigationController.tabBarItem = tabBarItem;






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

NSArray* controllers = [NSArray arrayWithObjects:self.infoViewController, self.navigationController, nil];

self.tabBarController = tbc; // retain property!

self.tabBarController.viewControllers = controllers; [tbc release];

Problem: I see a black Tab Bar at the bottom and a white content area. The first view controller in the array has a red background color. So it should appear red.

The Tab Bar shows no items, it's empty.

What can be the problem? I don't use nib files... No warnings, no errors, nothing logged to console. Just empty Tab Bar.

+1  A: 

Aren't you missing:

self.tabBarController.viewControllers = controllers;

EDIT:

Well other than that I don't see anything in the included code that is that wrong, so this leads me to think that something else must be wrong. A few options:

  1. Are you sure self.tabBarController points to anything (isn't nil)?
  2. Are you sure it's pointing to the same UITabController you're seeing?
  3. Are you sure the controllers you are creating are created correctly? Try displaying them regardless of the tabBar with

    [self.tabBarController presentModalViewController:iVC animated:YES];

  4. Is the UITabController created from a NIB? If it is put an NSLog on initWithNibName or awakeFromNib to make sure that it is called before your code, and not being called again after your code.

Start with these if none show any indication that something else is wrong, I can think of a few more things to try.

Ron Srebro
openfrog
see my updated answer
Ron Srebro