2017-03-21 136 views
0

我正在使用UITabBarController和UINavigationController進行應用程序。 視圖控制器圖如下所示:
UITabBarController選擇項顯示導航欄

TabBar Controller > Navigation Controller > View Controller 

在我設置的導航欄隱藏的第一個視圖控制器。但是,當我點擊TabBar項目來顯示其他視圖控制器,然後單擊返回到第一個視圖控制器導航欄顯示。每當我在所有其他視圖控制器補充說:

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    self.navigationController.navigationBarHidden = NO; 
} 

-(void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    self.navigationController.navigationBarHidden = YES; 
} 

任何人都知道如何在第一視圖控制器我的導航欄設置爲總是隱藏?請幫忙。 提前致謝。

+0

爲此,每個視圖控制器應該嵌入導航控制器中。之後,將所有導航控制器添加到標籤欄控制器。單導航控制器,它非常複雜。 – Pawan

+0

檢查答案可能有所幫助http://stackoverflow.com/questions/42120482/navigation-bar-is-moving-up-to-statusbar – Joe

回答

1

,如果你是在一些視圖控制器必須使用此方法:

[self.navigationController setNavigationBarHidden:YES animated:YES]; 

要隱藏的導航欄任何的viewController:

Objective-C的

- (void)viewWillAppear:(BOOL)animated { 
    [self.navigationController setNavigationBarHidden:YES animated:animated]; // Will hides Navigationbar 
    [super viewWillAppear:animated]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [self.navigationController setNavigationBarHidden:NO animated:animated]; // Will shows Navigationbar 
    [super viewWillDisappear:animated]; 
} 

Swift

override func viewWillAppear(animated: Bool) { 
    self.navigationController?.setNavigationBarHidden(true, animated: animated) 
    super.viewWillAppear(animated) 
} 

override func viewWillDisappear(animated: Bool) { 
    self.navigationController?.setNavigationBarHidden(false, animated: animated) 
    super.viewWillDisappear(animated) 
} 
+0

謝謝,它的工作! –

+0

快樂編碼:) –

1
If you have multiple tabs at bottom who follows structure: 

Controller > Navigation Controller > View Controller 

Then to hide navigation bar in first view controller, you need to use following code 

// TO HIDE NAVIGATION BAR in first view controller 

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    [self.navigationController setNavigationBarHidden:YES animated:animated]; 
} 

// TO SHOW NAVIGATION BAR in other view controllers 

If you want all other views should have navigation bar visible, you could use viewWillDisappear to set it to visible again. 


-(void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [self.navigationController setNavigationBarHidden:NO animated:animated]; 
} 
+0

我試過@Lal Krishna答案,它的工作。但也感謝你的幫助。 –

+0

歡迎@SonHoang –