当pushViewController时,UITabBarController消失

时间:2012-04-16 15:58:52

标签: iphone objective-c uinavigationcontroller uitabbarcontroller pushviewcontroller

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

有什么建议吗?

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

1 个答案:

答案 0 :(得分: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中,并将serounding navigationController添加到tabBar,而不是UIViewcontroller