简体   繁体   English

根据故事板中导航控制器的不同按钮调用相同标签栏控制器的特定选项卡

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

相关问题 故事板导航控制器和标签栏控制器 - Storyboard navigation controller and tab bar controller 按钮的IOS标签栏控制器(非标签) - IOS Tab Bar Controller for Buttons (not tabs) 如何在不同故事板的标签栏上显示拆分视图控制器? - How to show split view controller on tab bar from different storyboard? 如何在Main.storyboard中具有参考的其他Storyboard中为导航控制器设置选项卡图标和标题? - How to set tab bar icon and title for a Navigation controller in different Storyboard which has reference in Main.storyboard? 设置情节提要选项卡控制器,更多选项卡的导航栏颜色 - Setting a Storyboard Tab Controller, More Tab's Navigation Bar Colour 一个选项卡栏控制器中多个选项卡的一个导航控制器 - One navigation controller for multiple Tabs in a Tab Bar Controller 查看标签栏 controller 从 storyboard swift 5 - view tab bar controller from storyboard swift 5 选项卡栏控制器根据登录名隐藏选项卡-使用情节提要 - Tab Bar Controller hiding tabs depending on the Login - Using Storyboard 无法从选项卡栏控制器访问导航栏 - Navigation Bar not accessible from Tab Bar controller 具有导航控制器的标签栏控制器的导航控制器 - Navigation controller with tab bar controller of navigation controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM