在navigationController中推送控制器时如何隐藏父选项卡栏
我有一个带有选项卡栏控制器的应用程序,每个视图都包含一个导航控制器。我的主窗口如下所示: 图片位于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在花了几个小时并在这里发布问题后,我发现这个问题的解决方案是在 ArticleController 实例化之后添加以下行。
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.
如果您更喜欢情节提要配置而不是编码,则可以进行切换。只要去destinationViewController>属性检查器:
If you prefer storyboard configuration over coding there is a toggle for that. Just go destinationViewController > Attribute Inspector:
一个非常简单的解决方案:
对于您的情况:
希望这会有所帮助!
A very simple solution:
In your case:
Hope this helps!
您可以通过 Storyboard 简单地隐藏父选项卡栏。
选择视图控制器> 属性检查器 > 检查 按下时隐藏底部栏
You can simple hide parent tabbar through storyboard .
Select viewcontroller > Attribute Inspector > check Hide Bottom Bar on Push
您可以在您正在推送的视图控制器中添加以下代码。
这将仅隐藏推送视图控制器中的选项卡栏,并且当您弹出视图控制器选项卡栏时,在其余所有视图控制器中保持取消隐藏状态。
Swift 版本(3.x 及更高版本)
谢谢
You can add below code in the view controller, which you are pushing.
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)
Thanks
对于 swift 3,通过在pushviewController代码之前取消隐藏标签栏编写相同的代码,如下所示
,或者使用只是想要取消隐藏标签栏,你可以使用
for swift 3,write the same code by you unhide the tabbar before pushviewController code like below
or use just whant to unhide the tabbar u can use
在此处输入图像描述
转到 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!!
在要隐藏的控制器中使用属性
hidesBottomBarWhenPushed
。对于隐藏,所有控制器都放入
prepare for segue
Use property
hidesBottomBarWhenPushed
in the controller that you want to hide.For hide, all controllers put into
prepare for segue