2012-06-11 37 views
2

这里是我的一段代码,但这样,当我推动第三级视图控制器时,tabbar不会显示。UINavigationController,如何在第二级viewController中隐藏tabbar然后在第三级viewController中显示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]; 

回答

1

相反,当你初始化视图控制器设置hidesBottomBarWhenPushed的值,则应改为处理中的隐藏机制 - (空)viewWillAppear中:(BOOL)在视图控制器,而不是动画。

这种实现的一个例子是:

在SecondLevelViewController.m

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

在ThirdLevelViewController.m

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

它的工作原理。但我不知道为什么在推动第三级视图控制器时将hidesBottomBarWhenPushed属性设置为NO不起作用? –

+0

我假设hidesBottomBarWhenPushed是一个布尔变量不?如果它只是一个布尔变量,你不能指望它自己隐藏/显示视图。您需要在您的视图控制器中的某处实现隐藏/显示代码。在这个例子中,我在viewWillAppear方法中设置了隐藏/显示代码。 –

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]; 
} 
+0

我假设第一位代码应该封装在'viewDidLoad'方法中?另外,你可以添加一些关于这里发生的事情的解释吗? – 2012-06-11 12:40:56

相关问题