UINavigationController,如何在第二级viewController中隐藏tabbar然后在第三级viewController中显示tabbar

时间:2012-06-11 06:17:57

标签: ios

这是我的一段代码,但是这样,当我按下第三级视图控制器时,tabbar不会显示。

//at first level
SecondLevelViewController *_2vc = [[SecondLevelViewController alloc]initWithNibName:@"SecondLevelViewController" bundle:nil];
    _2vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:_2vc animated:YES];  

//at second level
ThirdLevelViewController *_3vc = [[ThirdLevelViewController alloc]initWithNibName:@"ThirdLevelViewController" bundle:nil];
    _3vc.hidesBottomBarWhenPushed = NO;
    [self.navigationController pushViewController:_3vc animated:YES];

2 个答案:

答案 0 :(得分:3)

    // Load the view
    AddViewController *aController = [[AddViewController alloc] init];

    // Set the view title
    aController.title = @"Add View";

    // hide tabbar
    aController.hidesBottomBarWhenPushed = YES;

    // add it to stack.
    [[self navigationController] pushViewController:aController animated:YES];

 -(void)viewWillAppear: (BOOL)animated
 {
    [super viewWillAppear:animated];
    [self.tabBarController.tabBar setHidden:YES];
 }

-(void)viewWillDisappear: (BOOL)animated 
{
    [super viewWillDisappear:animated];
    [self.tabBarController.tabBar setHidden:NO];
} 

答案 1 :(得分:1)

而不是在初始化视图控制器时设置hidesBottomBarWhenPushed的值,而是应该在视图控制器中动画的 - (void)viewWillAppear:(BOOL)中处理隐藏机制。

这种实现的一个例子是:

在SecondLevelViewController.m

-(void)viewWillAppear:(BOOL)animated
{
   [_bottomBar setHidden:YES];
}

在ThirdLevelViewController.m中

-(void)viewWillAppear:(BOOL)animated
{
   [_bottomBar setHidden:NO];
}