简体   繁体   English

选项卡不会以编程方式切换导航控制器中的tabBar

[英]tab does not switch programmatically for a tabBar inside a navigation controller

My app starts with a navigation controller which opens a UIViewController. 我的应用程序从一个导航控制器开始,该导航控制器打开一个UIViewController。 This screen works as a login page. 该屏幕用作登录页面。

On login, I open a UITabBarController like this: 登录时,我像这样打开一个UITabBarController:

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

Inside my tab bar controller, I want when clicking a button to switch tab programmatically. 在我的标签栏控制器中,我希望单击按钮以编程方式切换标签时。 I tried the following 3, neither of them worked. 我尝试了以下3种方法,但它们都不起作用。 Code is place inside a method, which is invoked when the button is clicked. 代码位于方法内部,单击该按钮时将调用该方法。

For the first 2, the tab didn't change - still my initial tab is highlighted and the correct view controller is not shown. 对于前两个,选项卡没有更改-仍然突出显示了我的初始选项卡,并且未显示正确的视图控制器。 For the last one, app crashes. 对于最后一个,应用程序崩溃。

1st : 第一:

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

2nd : 第二名

[self.parentViewController.tabBarController setSelectedIndex:1]; [self.parentViewController.tabBarController setSelectedIndex:1];

3rd: 第三:

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

What am I missing? 我想念什么?

for a tabBar inside a navigation controller...What am I missing? 导航控制器中的tabBar ...我缺少什么?

One thing you're missing is the order of containment that's allowed for view controllers. 您缺少的一件事是视图控制器允许的包含顺序 Specifically, you can put a navigation controller inside a tab controller, but not the other way around. 具体来说,您可以将导航控制器放在选项卡控制器中,但不能反过来。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从单独的导航控制器切换TabBar项目 - Switch TabBar Item from separate Navigation Controller 标签栏未显示在导航控制器内的视图控制器上 - Tab Bar does not show on View Controller inside Navigation Controller Swift:通过TabBar和导航控制器以编程方式从一个视图过渡到另一个视图 - Swift: Programmatically transitioning from 1 view to another via a TabBar and Navigation Controller iOS Swift Tabbar Controller以编程方式添加项(新选项卡) - iOS Swift Tabbar Controller Add Item (new tab) programmatically 如何以编程方式从位于导航控制器内部的视图控制器移动标签栏? - How to programmatically moving tab bar from a view controller located inside navigation controller? TabBar 和导航控制器 - TabBar and Navigation Controller 以编程方式切换到另一个选项卡并切换到第一个视图控制器? - Programmatically switch to another tab AND switch to the first view controller? 以编程方式在子视图中切换选项卡栏视图(自定义选项卡栏控制器) - Switch tab bar view in subview programmatically (custom tab bar controller) 将导航控制器实现到标签栏控制器中 - Implement a navigation controller into a tabbar controller 如何以编程方式显示具有情节提要中定义的导航控制器和标签栏控制器的控制器? - How to programmatically show a controller that has a navigation controller and tabbar controller as defined in a storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM