簡體   English   中英

UINavigationController,如何在第二級viewController中隱藏選項卡,然后在第三級viewController中顯示選項卡

[英]UINavigationController, how to hide tabbar in second level viewController then show tabbar in third level viewController

這是我的一部分代碼,但是以這種方式,當我按下第三級視圖控制器時,標簽欄將不會顯示。

//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];
    // 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];
} 

代替在初始化視圖控制器時設置hidesBottomBarWhenPushed的值,而應在視圖控制器中設置動畫的-(void)viewWillAppear:(BOOL)中處理隱藏機制。

此實現的示例為:

在SecondLevelViewController.m中

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

在ThirdLevelViewController.m中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM