Fahim Parkar
Fahim Parkar

Reputation: 31657

how to go to tab bar controller after clicking the respective button

I have structure of project as shown below.

enter image description here

On the left side I have MainViewController. There I have two buttons as English and Arabic. What I want to do is when I click English, I want to go English tab bar controller (HomeViewController).

Hence what I wrote is

- (IBAction)langEnglish:(id)sender {
    HomeViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"enghome"];
    [self.navigationController pushViewController:secondView animated:YES];
}

This is working perfectly, but I don't see tab bar.

Tab bar is missing from this.

Any idea what is going wrong?


Basically what I have is view controller as main controller and upon clicking button on this controller, tab view controller should get open...

Upvotes: 3

Views: 4539

Answers (3)

Fahim Parkar
Fahim Parkar

Reputation: 31657

What I did is as below

- (IBAction)langEnglish:(id)sender {
    EngTabViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"engtab"];
    [self.navigationController pushViewController:secondView animated:YES];
}

EngTabViewController is the UITabBarController and I assigned id to tab bar controller... this works like charm...

Means instead of viewcontorller, I used tabbarcontroller...

Upvotes: 1

Kevin
Kevin

Reputation: 1506

You shouldn't push a UITabBarController on a UINavigationController. Set it as the window's root view controller instead and the tab bar should be displayed as expected.

Upvotes: 0

Abdullah Shafique
Abdullah Shafique

Reputation: 6918

Go to your main storyboard and select your main view controller. On top select Editor->Embed in->navigation bar.

EDIT: If this does not work push to your tab bar and use this code:

self.tabBarController.selectedIndex = 1;

Upvotes: 3

Related Questions