How to hide parent tabbar when pushing controller

2019-01-22 12:55发布

I have an application with a tab bar controller and each view contains a navigation controller. My MainWindow looks as follows: alt text http://www.freeimagehosting.net/image.php?7bc867a594.png

Everything works fine as it is but I noticed a problem when pushing a details view to the navigation controller. In the didSelectRowAtIndexPath for a tableviewcontroller that belongs to the tab bar controller (the one called Latest in the image) I am doing this:

- (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;

}

The ArticleViewController has its own tabbar because it needs to display different things. The problem is that when I push the ArticleViewController into the navigationController I see both tabbars at the bottom of the view. Is there any way I can solve this problem?

Thanks in advance

7条回答
叼着烟拽天下
2楼-- · 2019-01-22 13:08

If you prefer storyboard configuration over coding there is a toggle for that. Just go destinationViewController > Attribute Inspector:

enter image description here

查看更多
唯我独甜
3楼-- · 2019-01-22 13:10

for swift 3,write the same code by you unhide the tabbar before pushviewController code like below

   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)

or use just whant to unhide the tabbar u can use

  viewController.hidesBottomBarWhenPushed = false
查看更多
霸刀☆藐视天下
4楼-- · 2019-01-22 13:12

A very simple solution:

 destinationViewController.hidesBottomBarWhenPushed = YES;

In your case:

 articleController.hidesBottomBarWhenPushed = YES;

Hope this helps!

查看更多
家丑人穷心不美
5楼-- · 2019-01-22 13:22

After spending hours and posting a question here I found that the solution to this problem is adding the following line after the instantiation of ArticleController.

articleController.hidesBottomBarWhenPushed = YES;
查看更多
一夜七次
6楼-- · 2019-01-22 13:29

You can simple hide parent tabbar through storyboard .

Select viewcontroller > Attribute Inspector > check Hide Bottom Bar on Push

查看更多
淡お忘
7楼-- · 2019-01-22 13:29

enter image description here

Go to interface builder in Xcode -> open attribute inspector and check the item 'Hide Bottom bar on Push' for view controller you don't want to show tab bar. It will work!!

查看更多
登录 后发表回答