在iOS上隐藏几页的UINavigationBar

时间:2012-10-09 05:34:12

标签: iphone ios cocoa-touch

我的AppDelegate代码UINavigationBar中包含此代码:

NSArray *viewsArray;

ToolsViewController *toolsnavigation = [[ToolsViewController alloc] initWithNibName:@"ToolsViewController" bundle:nil];
toolsnavigation.tabBarItem.image = [UIImage imageNamed:@"setting_image.png"];
[toolsnavigation setTitle:@"Tools"];
UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:toolsnavigation];

MyrideViewController *myridenavigation = [[MyrideViewController alloc] initWithNibName:@"MyrideViewController" bundle:nil];
myridenavigation.tabBarItem.image = [UIImage imageNamed:@"bottom_nav_image_2.png"];
[myridenavigation setTitle:@"My Ride"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:myridenavigation];

NewsViewController *newsnavigation = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
newsnavigation.tabBarItem.image = [UIImage imageNamed:@"bottom_nav_image_3.png"];
[newsnavigation setTitle:@"News"];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:newsnavigation];

CoolViewController *coolnavigation = [[CoolViewController alloc] initWithNibName:@"CoolViewController" bundle:nil];
coolnavigation.tabBarItem.image = [UIImage imageNamed:@"bottom_nav_image_4.png"];
[coolnavigation setTitle:@"Cool"];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:coolnavigation];

AccidentViewController *accidentnavigation = [[AccidentViewController alloc] initWithNibName:@"AccidentViewController" bundle:nil];
accidentnavigation.tabBarItem.image = [UIImage imageNamed:@"bottom_nav_image_5.png"];
[accidentnavigation setTitle:@"Accident"];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:accidentnavigation];

viewsArray = [NSArray arrayWithObjects:nav0,nav1,nav2,nav3,nav4, nil];
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0,0,320,460);

[tabbarController setViewControllers:viewsArray];

self.window.rootViewController = tabbarController;

有了这个,UINavigationBar出现在每一页上。我希望它在几页之后出现,例如一旦用户登录了旅馆,就会出现导航栏。我当前的代码不会发生这种情况。我该如何解决这个问题?

This is the screenshort of the navigation bar which is coming on the login page too

2 个答案:

答案 0 :(得分:0)

使用导航栏的栏隐藏属性,无论您希望隐藏哪个

controllerObject.navigationController.navigationBar.hidden = YES;

在您的情况下添加

nav0.navigationBar.hidden = YES;
行后

UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:toolsnavigation];

答案 1 :(得分:0)

LoginView的 viewDidLoad

[self.navigationController.navigationBar setHidden:YES];  

然后在其他视图中

[self.navigationController.navigationBar setHidden:NO];