0

I am new in iOS world.I am creating one tab-bar sample app.

There is one button in first view-controller when i click this button it goes to to second view-controller.In second view-controller i use one gridview and i left 100 space at bottom.

now in second view-controller i have to add one tab bar so i go to Editor->Embedin->Tabbar controller and run application but i do not see tab bar here.I also try to use tab bar controller on object library but same issue i found.

Why tab bar is not displaying in second view-controller.Any suggestion ?

button click event :-

SecondVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];

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

Thanks .

Bhumika
  • 876
  • 7
  • 20
arpit
  • 555
  • 1
  • 7
  • 25
  • Can you please post your code. Button click event – Puvanarajan Jul 01 '16 at 10:11
  • SecondVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"]; [self.navigationController pushViewController:vc animated:YES]; – arpit Jul 01 '16 at 10:13
  • I guess, You are calling directly the second viewcontroller. That's why it is loading the second view controller. – Puvanarajan Jul 01 '16 at 10:18
  • 1
    http://stackoverflow.com/questions/22748354/ios-push-to-tabbarcontroller – Puvanarajan Jul 01 '16 at 10:22
  • yes this is app requirement, second view controller has tabbar but it is not displaying. any suggestion how can i call second view controller with tab bar. I add tab bar controller on second view controller but why it is not displaying ? can you please help . – arpit Jul 01 '16 at 10:23
  • In short, you can't do it ! – Proton Jul 01 '16 at 10:26
  • @Proton Actually it's my project requirement when i click one button in first view controller and then in second view controller have grid view with tab bar. Any suggestion – arpit Jul 01 '16 at 10:34
  • From 1st view controller, you should `present` to 2nd view controller. In 2nd VC, you can add new tabbar – Proton Jul 01 '16 at 10:38

2 Answers2

1

If you have the SecondVC embedded in a TabBarVC you need to present the TBVC instead of the SecondVC in order for the Tab Bar to actually appear.

So instead of doing:

SecondVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];

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

you need to do:

TabBarVC *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"TabBarVC"];

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

This will add to the navigation stack the Tab Bar View Controller.

This might be the implementation you are looking for TabBarVC inside NavC

APesate
  • 100
  • 12
  • I have one more issue after this. After click on button it goes to tab bar now but when i press back button the application crash and show me this error:- "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't add self as subview' " if i check it on google and change animation yes to no so it did not crash:- [self.navigationController pushViewController:vc animated:NO]; but when i click on first time back button it goes to again tabbar controller ie. embeded in second vc if i press second time back button now they go to first vc. any suggestion ? – arpit Jul 02 '16 at 06:49
  • @arpit I'm not sure I understood correctly the problem, but sounds like this http://stackoverflow.com/a/21226801/2745324 – APesate Jul 02 '16 at 12:41
0

Button to viewcontroller SecondVC set segue identifer name as Pass

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{if ([[segue identifier] isEqualToString:@"Pass"])
{
SecondVC* vc = [[SecondVC alloc] init];

vc = (SecondVC ) [[(UINavigationController)[[self.tabBarController viewControllers] objectAtIndex:0] viewControllers] objectAtIndex:0];

}
}
Rajaguhan
  • 16
  • 2