[英]Calling particular tabs of same tab bar controller based on different buttons from navigation controller in storyboard
My Application's Workflow: 我的应用程序的工作流程:
Here, I have 1 one Main Navigation Controller .Then, it push to 1 Tabbar Controller & 2 View Controllers . 在这里,我有一个主导航控制器 。然后,它推送到1个Tabbar控制器和2个视图控制器 。
Main Tabbar Controller has 2 different navigation controllers for individual functionalities. 主Tabbar控制器有2个不同的导航控制器,用于各种功能。
Now, I want to navigate to Main Tabbar from button 1 & button 2. 现在,我想从按钮1和按钮2导航到主标签栏。
When I pressed, button 1, it will shift to 2nd Tab & when I pressed button 2, it will shift to 3rd tab as I described in an image. 当我按下按钮1时,它将切换到第二个标签,当我按下按钮2时,它将按照我在图像中描述的那样切换到第三个标签。
I am using self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
我正在使用
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
code for shifting tab. 转换标签的代码。
It's shifting, but not calling ViewDidLoad
method of that class & not loading data accordingly. 它正在转移,但不会调用
ViewDidLoad
方法而不会相应地加载数据。
So, how to call particular tab based on button's click ?? 那么,如何根据按钮的点击调用特定选项卡?
Any suggestions will be appreciated. 任何建议将不胜感激。
Thanks in advance. 提前致谢。
您需要尝试使用以下代码段
<tabbar_controller_object>.selectedIndex = <YOUR_tab_no_to_select>;
You can use self.tabBarController.selectedIndex = yourIndex;
你可以使用
self.tabBarController.selectedIndex = yourIndex;
as Foram Mukund Shah has said. 正如Foram Mukund Shah所说。
But, as you want to change the index, you need to write this code in viewDidAppear
rather than on viewDidLoad
it is not changing because you are trying to change index before your tabbar is loaded. 但是,由于您想要更改索引,您需要在
viewDidAppear
而不是viewDidLoad
编写此代码,因为您在加载tabbar之前尝试更改索引,因此它不会更改。
So, please try to put your code in viewDidAppear
. 所以,请尝试将您的代码放在
viewDidAppear
。
It will resolve your issue. 它将解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.