【问题标题】:tab does not switch programmatically for a tabBar inside a navigation controller选项卡不会以编程方式切换导航控制器内的 tabBar
【发布时间】:2014-05-25 01:34:37
【问题描述】:

我的应用程序从打开 UIViewController 的导航控制器开始。此屏幕用作登录页面。

登录时,我像这样打开一个 UITabBarController:

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:@"MainTab"];
    self.navigationController.navigationBarHidden=YES;
    [self.navigationController pushViewController:obj animated:YES];

在我的标签栏控制器中,我希望在单击按钮时以编程方式切换标签。我尝试了以下 3 个,但都没有工作。代码放置在方法中,单击按钮时调用该方法。

对于前 2 个,选项卡没有更改 - 我的初始选项卡仍然突出显示,并且未显示正确的视图控制器。对于最后一个,应用程序崩溃。

第一:

  self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];

第二个:

[self.parentViewController.tabBarController setSelectedIndex:1];

第三:

UITabBarController *MyTabController = (UITabBarController *)((AppDelegate*) [[UIApplication sharedApplication] delegate]).window.rootViewController;
[MyTabController setSelectedIndex:1];

我错过了什么?

【问题讨论】:

    标签: ios uinavigationcontroller uitabbarcontroller


    【解决方案1】:

    对于导航控制器内的 tabBar...我错过了什么?

    您缺少的一件事是视图控制器允许使用的order of containment。具体来说,您可以将导航控制器放在选项卡控制器中,但不能反过来。

    【讨论】:

      猜你喜欢
      • 2011-07-21
      • 1970-01-01
      • 2023-03-20
      • 2020-01-15
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多