user1385666 user1385666 - 3 months ago 11
Objective-C Question

hide UITabBarController's tab bar when pushing UIViewController

I have a tab bar application.
Here's launching code

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Override point for customization after application launch.
[self.window makeKeyAndVisible];



self.tabBarController=[[UITabBarController alloc] init];


StartViewController *startViewController=[[StartViewController alloc] initWithNibName:@"StartViewController" bundle:nil];
NavRootViewController *navRootViewController=[[NavRootViewController alloc] initWithNavControllerWithSubViewController:startViewController];

HelpViewController *helpViewController=[[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];

SettingsViewController *settingsViewController=[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];

AboutUsViewController *aboutUsViewController=[[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];

[self.tabBarController setViewControllers:[NSArray arrayWithObjects: navRootViewController, helpViewController, settingsViewController, aboutUsViewController, nil]];



[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController=self.tabBarController;


Application launched with 4 tab bar tabs.
This action is called after user presses start button in the first tab's navigation controller's root view controller

-(IBAction)startPressed:(id)sender
{
NSLog(@"startPressed: called");


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

}


This works fine but I need to hide tab bar for my
RootViewController

property
hidesBottomBarWhenPushed
does not work.
Help me please, how can it be done?

Answer

Yea you have to add the modalview on window not on the viewcontroller of tabBar. Try something like.. make an object of AppDelegate like: AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate]; then in next line add

[appDelegate.window.rootviewcontroller.view presentModalViewController:vController animated:YES];

or add your code [self presentModalViewController:vController animated:YES] in the viewDidAppear of the firstviewcontroller of tabBar.

What did you do to solve the problem??I would like to know that also.