【问题标题】:UITabBarController disappears when pushViewControllerpushViewController 时UITabBarController 消失
【发布时间】:2012-04-27 23:40:10
【问题描述】:

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

有什么建议吗?

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

【问题讨论】:

  • 你能把代码贴在你推送下一个viewController的地方吗?

标签: iphone objective-c uinavigationcontroller uitabbarcontroller pushviewcontroller


【解决方案1】:

这可能是因为您的 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];

}

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

【讨论】:

  • 如何将 TabBar 设置为 rootController?
  • 好的,但我一开始没有 tabBar。我有一个登录视图,然后是 tabBarController。有什么安排这个的建议吗?
  • LoginViewcontroller 将成为您的 rootViewController,在成功登录后初始化标签栏,并通过调用 pushViewController:tabBar 导航到它
  • 好的,这就是我实际在做的事情,但是将导航控制器作为根控制器。但是当我按下我的 tabBar 时,我也可以按下 tableView 的一个单元格并按下它,我的 tabBar 就在那里消失了......
  • 另外,如果我的根控制器是 LoginViewcontroller,如何使用 pushViewController:tabBar 导航到 tabBar?我没有任何 NavigationController...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-29
  • 1970-01-01
  • 2018-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多