1

我正在尝试将 TTThumbsViewController 放在 UITabBarController 中,但是当我这样做时,TTThumbsViewController 的 NavigationBar 不显示。NavigationBar 应该在的地方只有空白。我自己只加载了 TTThumbsViewController,而 NavigationBar 加载得很好。我确定我只是错过了一个设置,但我无法弄清楚它是什么。

下面是我创建 UITabBarController 和 TTThumbsViewController 的方法:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:thumbsViewController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
4

1 回答 1

2

如果您从 UITabController 加载 TTThumbsViewController,则需要自己创建 UINavigationController。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.tabBarController = [[UITabBarController alloc] init];
    ThumbsViewController *thumbsViewController = [[ThumbsViewController alloc] init];
    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Thumbs" image:[UIImage imageNamed:@"icon.png"] tag:Thumbs];
    thumbsViewController.tabBarItem = thumbsTabBarItem;

    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:ThumbsViewController] autorelease];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
于 2011-08-02T14:26:33.163 回答