2012-06-11 44 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

相關問題