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条回答
smile是对你的礼貌
2楼-- · 2019-01-22 13:30

You can add below code in the view controller, which you are pushing.

-(BOOL)hidesBottomBarWhenPushed
{ 
     return YES;
}

This will hide the tabbar in the pushed view controller only and as you pop the view controller tabbar remains unhide in rest all view controllers.

Swift version (3.x and above)

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

Thanks

查看更多
登录 后发表回答