1

我有一个带有 UITabBar 和 NavigationController 的应用程序。当我使用 pushViewController 时,新的 ViewController 与 NavigationController 和后退按钮一起出现,但 UITabBarController 消失了。我知道这里有很多相同的问题,但其中任何一个都解决了我的问题,也许是因为我不明白给出的答案。

有什么建议吗?

    ActivityViewController *activityController = [[ActivityViewController alloc] initWithNibName:@"ActivityViewController" bundle:nil];
    [self.navigationController pushViewController:activityController animated:NO];
4

1 回答 1

4

这可能是因为您的 rootViewController(用于您的主 UIWindow)设置为 Navigationcontroller 而不是您的 TabBar。如果您不希望 Tabbar 消失,只需将其设置为您的根视图控制器

在 AppDelegate 的 appDidFinishLaunching 中执行以下操作

LoginViewController *loginViewController = [[FirstViewController alloc] init];
UINavigationController *loginNavigationController = [[UINavigationController alloc] loginViewController];
[firstViewController release];

self.window.rootViewController = loginNavigationController;

然后在您的登录页面中:

- (void)loginSuccessfull
{
    FirstViewController *firstViewController = [[FirstViewController alloc] init];
    UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithViewController:firstViewController];
    [firstViewController release];

    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithViewController:secondViewController];
    [secondViewController release];


    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [tabBarController setViewControllers:
[NSArray arrayWithObjects:firstNavigationController, secondNavigationController, nil]];

    [firstNavigationController release];
    [secondNavigationController release];

    [self.navigationController pushViewController:tabBarController];
    [tabBarController release];

}

如果您仍然需要导航功能,只需将您的 viewControllers 包装在 UINavigationController 中,并将周围的 navigationController 添加到 tabBar,而不是 UIViewcontroller

于 2012-04-16T16:06:59.703 回答