xcode 在 iPhone 中显示/隐藏 TabBarController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1356828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Show/Hide TabBarController in iphone
提问by David.Chu.ca
i am making an application in iphone in which i have 4 tabbars & in one of its tab i have 4 views in 2nd view it needs to hide the tab bar. I am able to hide the tab bar using the setHidesBottomBarWhenPushed:YES in in the initWithNib method of the Viewcontroller being pushed. But when navigating to the screen 3 , calling the same method with "NO" does not make the tab bar appear. any ideas?
我正在 iphone 中制作一个应用程序,其中我有 4 个标签栏,并且在它的一个标签中,我在第二个视图中有 4 个视图,它需要隐藏标签栏。我可以在被推送的 Viewcontroller 的 initWithNib 方法中使用 setHidesBottomBarWhenPushed:YES 隐藏标签栏。但是当导航到屏幕 3 时,使用“NO”调用相同的方法不会使标签栏出现。有任何想法吗?
回答by esilver
John Smith is correct. The URL for that sample is: http://developer.apple.com/iphone/library/samplecode/TheElements/index.html
约翰史密斯是对的。该示例的 URL 是:http: //developer.apple.com/iphone/library/samplecode/TheElements/index.html
The code that does this is in AtomicElementViewController.m, and the line that achieves this effect is in the init method:
执行此操作的代码在 AtomicElementViewController.m 中,实现此效果的代码在 init 方法中:
self.hidesBottomBarWhenPushed = YES;
回答by David.Chu.ca
I had the same issue to show or hide tab bar controller with UITableViewController customized class. Somehow, by using the following codes, does not work to hide tab bar controller:
我在使用 UITableViewController 自定义类显示或隐藏标签栏控制器时遇到了同样的问题。不知何故,通过使用以下代码,无法隐藏标签栏控制器:
- (void) viewDidLoad {
self.hidesBottomBarWhenPushed = YES;
}
In the case of storyboard with segue, initWithStyle: method does not get called.
在带有 segue 的情节提要的情况下,不会调用 initWithStyle: 方法。
Instead, I have to overwrite the property to make it work:
相反,我必须覆盖该属性才能使其工作:
- (BOOL) hidesBottomBarWhenPushed {
return YES;
}
My case is for iOS 5.1 with storyboard and segue to push to the next view (where I want to hide tab bar controller).
我的情况是 iOS 5.1 的故事板和 segue 推送到下一个视图(我想隐藏标签栏控制器的地方)。
回答by John Smith
Take a look at Apple's Elements projects. They hide and unhide the tab-bar when you view and individual element.
看看 Apple 的 Elements 项目。当您查看单个元素时,它们会隐藏和取消隐藏标签栏。
回答by Jay
Before you push your 3rd view onto the stack, set the 2nd view's hidesBottomBarWhenPushed to NO.
在将第三个视图推入堆栈之前,将第二个视图的 hidesBottomBarWhenPushed 设置为 NO。