在navigationController中推送控制器时如何隐藏父选项卡栏

发布于 2024-09-03 20:23:12 字数 867 浏览 11 评论 0原文

我有一个带有选项卡栏控制器的应用程序,每个视图都包含一个导航控制器。我的主窗口如下所示: 图片位于 http://www.freeimagehosting.net/image.php ?7bc867a594.png

一切正常,但我在将详细信息视图推送到导航控制器时注意到一个问题。在属于选项卡栏控制器(图中称为“最新”的控制器)的 tableviewcontroller 的 didSelectRowAtIndexPath 中,我这样做:

- (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 有自己的选项卡栏,因为它需要显示不同的内容。问题是,当我将 ArticleViewController 推入 navigationController 时,我在视图底部看到两个选项卡栏。我有什么办法可以解决这个问题吗?

提前致谢

I have an application with a tab bar controller and each view contains a navigation controller. My MainWindow looks as follows: Image here 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

橘味果▽酱 2024-09-10 20:23:12

在花了几个小时并在这里发布问题后,我发现这个问题的解决方案是在 ArticleController 实例化之后添加以下行。

articleController.hidesBottomBarWhenPushed = YES;

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;
触ぅ动初心 2024-09-10 20:23:12

如果您更喜欢情节提要配置而不是编码,则可以进行切换。只要去destinationViewController>属性检查器:

在此处输入图像描述

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

enter image description here

贪恋 2024-09-10 20:23:12

一个非常简单的解决方案:

 destinationViewController.hidesBottomBarWhenPushed = YES;

对于您的情况:

 articleController.hidesBottomBarWhenPushed = YES;

希望这会有所帮助!

A very simple solution:

 destinationViewController.hidesBottomBarWhenPushed = YES;

In your case:

 articleController.hidesBottomBarWhenPushed = YES;

Hope this helps!

如梦亦如幻 2024-09-10 20:23:12

您可以通过 Storyboard 简单地隐藏父选项卡栏。

选择视图控制器> 属性检查器 > 检查 按下时隐藏底部栏

You can simple hide parent tabbar through storyboard .

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

满身野味 2024-09-10 20:23:12

您可以在您正在推送的视图控制器中添加以下代码。

-(BOOL)hidesBottomBarWhenPushed
{ 
     return YES;
}

这将仅隐藏推送视图控制器中的选项卡栏,并且当您弹出视图控制器选项卡栏时,在其余所有视图控制器中保持取消隐藏状态。

Swift 版本(3.x 及更高版本)

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

谢谢

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

是伱的 2024-09-10 20:23:12

对于 swift 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)

,或者使用只是想要取消隐藏标签栏,你可以使用

viewController.hidesBottomBarWhenPushed = false

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
萌面超妹 2024-09-10 20:23:12

在此处输入图像描述

转到 Xcode 中的界面生成器 ->打开属性检查器并检查您不想显示选项卡栏的视图控制器的“推送时隐藏底部栏”项目。会起作用的!!

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!!

儭儭莪哋寶赑 2024-09-10 20:23:12

在要隐藏的控制器中使用属性 hidesBottomBarWhenPushed

对于隐藏,所有控制器都放入 prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}

Use property hidesBottomBarWhenPushed in the controller that you want to hide.

For hide, all controllers put into prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文