0

我像这样创建了一个 UITabBarController:

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 = 控制器;[待定发布];

问题:我看到底部有一个黑色的标签栏和一个白色的内容区域。数组中的第一个视图控制器具有红色背景色。所以它应该显示为红色。

标签栏不显示任何项目,它是空的。

可能是什么问题?我不使用 nib 文件...没有警告,没有错误,没有任何记录到控制台。只需清空标签栏。

4

1 回答 1

1

你是不是错过了:

self.tabBarController.viewControllers = controllers;

编辑:

好吧,除此之外,我在包含的代码中没有看到任何错误的东西,所以这让我认为其他东西一定是错误的。几个选项:

  1. 你确定 self.tabBarController 指向任何东西(不是零)吗?
  2. 你确定它指向你看到的同一个 UITabController 吗?
  3. 你确定你正在创建的控制器是正确创建的吗?尝试显示它们,而不考虑 tabBar

    [self.tabBarController presentModalViewController:iVC 动画:YES];

  4. UITabController 是从 NIB 创建的吗?如果将 NSLog 放在 initWithNibName 或 awakeFromNib 上,以确保在您的代码之前调用它,而不是在您的代码之后再次调用它。

从这些开始,如果没有任何迹象表明有其他问题,我可以考虑更多尝试。

于 2010-01-26T13:54:58.750 回答