0
votes

I have a navigation controller which has view controller(VC1) . This view controller has 3 button out of which 1 directs to a tab bar controller. From tab1 of the tab bar controller a button is there which navigates to a View controller(vc2). The problem is VC2 is not displaying the tab bar. How can I make my VC2 display the tab bar.

Navigation Controller—> View Controller-->Tab bar Controller —>Tab1 -> View Controller (does not show tab bar)

I am doing this in IOS

1
Show some code. Is vc2 in the tab controller, or being presented by it (presentViewController:animated:completion:)?Wain
I am trying to do this by adding components to storyboard. I haven't written code for this. From Tab 1, I have given a Push Segue to vc2user1882758
@user1882758 - If your are using storyboard - put pic of the same in questionbhavya kothari

1 Answers

0
votes

Using a tabbarcontroller within a navigation controller is not recommended by Apple. However it is possible to do so. In the VC1, write the following code.

UITabBarController *tabBarController =  [[UITabBarController alloc] init];

MyStartViewController *startController = [[MyStartViewController alloc] initWithNibName:@"MyStartViewController" bundle:Nil];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:startController];

SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

self.viewControllers = @[navController, viewController2];

[self.navigationController pushViewController:tabBarController animated:YES];

Now within startController, add a UIButton. And in the button action, push the new VC2 from it.

Button action:

- (IBAction)buttonPressed {

   MyViewController2 *vc2 = [[MyViewController2 alloc] initWithNibName:@"MyViewController2" bundle:nil];
   [self.navigationController pushViewController:vc2 animated:YES];

}

Hope this will serve your purpose.