2010-06-01 56 views
18

我有一個帶有標籤欄控制器的應用程序,每個視圖都包含一個導航控制器。我的主窗口看起來如下:alt text http://www.freeimagehosting.net/image.php?7bc867a594.png如何在navigationController中按控制器時隱藏父Tabbar

一切正常,因爲它是,但我注意到一個問題時,推送到導航控制器的詳細信息視圖。在didSelectRowAtIndexPath方法對屬於標籤欄控制器tableviewcontroller(一個叫圖像最新)我這樣做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
ArticleViewController *articleController = [[ArticleViewController alloc] initWithNibName:@"ArticleView" bundle:nil]; 

[self.navigationController pushViewController:articleController animated:YES]; 

[articleController release]; 
articleController = nil; 

}

的ArticleViewController都有自己的TabBar,因爲它需要顯示不同的東西。問題是,當我將ArticleViewController推入navigationController時,我在視圖底部看到了兩個tabbars。有什麼辦法可以解決這個問題嗎?

在此先感謝

回答

61

花費時間和發佈提問後,在這裏我發現,解決這個問題是添加ArticleController的實例後,下面一行。

articleController.hidesBottomBarWhenPushed = YES; 
+1

太謝謝你了!這就像魅力一樣!你讓我今天一整天都感覺很好! – Tommy 2017-12-07 02:02:31

+0

重要注意事項是在創建targetViewController後立即設置了'hidesBottomBarWhenPushed' – 2018-01-28 17:18:27

7

一個非常簡單的解決方案:

destinationViewController.hidesBottomBarWhenPushed = YES; 

你的情況:

articleController.hidesBottomBarWhenPushed = YES; 

希望這有助於!

17

如果您更喜歡故事板配置而不是編碼,那麼可以使用切換鍵。剛去destinationViewController>屬性檢查器:

enter image description here

+1

我不知道爲什麼這是低調投票,但這確實對我有用。 – iSee 2016-01-02 16:03:21

0

您可以在視圖控制器,你正在推動添加下面的代碼。

-(BOOL)hidesBottomBarWhenPushed 
{ 
    return YES; 
} 

這將隱藏在只有和你彈出視圖控制器的TabBar的推視圖控制器使用TabBar保持在休息取消隱藏所有視圖控制器。

斯威夫特版本(3.x和以上)

override var hidesBottomBarWhenPushed: Bool { 
    get { 
     return navigationController?.topViewController == self 
    } 
    set { 
     super.hidesBottomBarWhenPushed = newValue 
    } 
} 

感謝

0

的迅速3,在你面前pushviewController代碼像下面

var frame = self.tabBarController?.tabBar.frame 
    frame?.origin.y = self.view.frame.size.height - (frame?.size.height)!+112 
    UIView.animate(withDuration: 0.2, animations: { 
     self.tabBarController?.tabBar.frame = frame! 
    }) 
    self.navigationController?.pushViewController(viewController, animated: true) 

取消隱藏的TabBar寫相同的代碼或者只是用whant取消隱藏標籤欄,你可以使用

viewController.hidesBottomBarWhenPushed = false 
0

enter image description here

進入界面生成器在Xcode - >打開屬性檢查,檢查項目「隱藏的推底部欄」您不希望顯示標籤欄視圖控制器。它會工作!

1

您可以通過故事板簡單地隱藏父母tabbar。

選擇視圖 - 控制>屬性檢查器>檢查隱藏底欄上推