[英]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.