0

I would like to have a UIViewController with a UIButton. After the user has pressed the button, the UITabBarController should appear with deferent tabs.

UIViewController *view1 = [[FirstViewController alloc] 
UIViewController *view2 = [[SecondViewController alloc] 
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[view1, view2];

How can I show a view before the UITabBarController?

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    What does this have to do with `UITabBarController`? You setup your app with whatever view hierarchy you need. Showing a tab controller is no different than showing any other view controller. – rmaddy Jan 21 '15 at 19:29
  • I agree with rmaddy, you can just modally navigate to a UITabBarController from the root Vc with that button. – Jargen89 Feb 19 '15 at 14:26

2 Answers2

0

You can achieve this right from appDeleguate, you would use setRootViewController to set the screen to present.

Example:

ButtonViewController *btnVC = [[ButtonViewController alloc]init];
[self.window setRootViewController:btnVC];

Example with NavigationController:

ButtonViewController *btnVC = [[ButtonViewController alloc]init];
[self.window setRootViewController:btnVC];
UINavigationController *navController=[[UINavigationController alloc]
                                                     initWithRootViewController:btnVC];
[self.window setRootViewController:navController];
meda
  • 45,103
  • 14
  • 92
  • 122
  • It doesn't work properly because I have a UINavigationController already. Do you have any other suggestions? Thanks :) – user1211109876 Jan 21 '15 at 19:27
  • Ok I think we are on the right track! However, when I am on the UITabBarController, a black screen with a tabBar is shown, that has no items in it. Is there a way to fix that? Thanks – user1211109876 Jan 21 '15 at 19:42
  • @user1211109876 if you see a black screen then it must be your view not being hooked up to the controller. Read the following answers if [you are using a storyboard](http://stackoverflow.com/a/18331941/1880431) or this answer if [you are using nibs](http://stackoverflow.com/a/2225024/1880431) or you can do design through code – meda Jan 22 '15 at 01:01
0

Set up your tab controller as the root view controller, as usual. Then present a modal view controller with your button. When the button is pushed, dismiss the modal view controller.

Brian
  • 15,599
  • 4
  • 46
  • 63