Manann Sseth
Manann Sseth

Reputation: 2745

Calling particular tabs of same tab bar controller based on different buttons from navigation controller in storyboard

My Application's Workflow:

Application Workflow

Here, I have 1 one Main Navigation Controller.Then, it push to 1 Tabbar Controller & 2 View Controllers.
Main Tabbar Controller has 2 different navigation controllers for individual functionalities.

Now, I want to navigate to Main Tabbar from button 1 & button 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.

I am using 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.

So, how to call particular tab based on button's click ??

Any suggestions will be appreciated.

Thanks in advance.

Upvotes: 0

Views: 711

Answers (2)

Akbari Dipali
Akbari Dipali

Reputation: 2173

You can use self.tabBarController.selectedIndex = yourIndex; as Foram Mukund Shah has said.

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.

So, please try to put your code in viewDidAppear.

It will resolve your issue.

Upvotes: 1

Niru Mukund Shah
Niru Mukund Shah

Reputation: 4733

You need to try with following snippet once

<tabbar_controller_object>.selectedIndex = <YOUR_tab_no_to_select>;

Upvotes: 1

Related Questions