xcode 如何在标签栏控制器中从一个视图控制器切换到另一个并保留标签栏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9694724/
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
How within a tab bar controller do I segue from one view controller to another and retain the tab bar?
提问by John
I have an application with several view controllers controlled from a tab bar controller. From one of these view controllers I want to (on clicking a button) segue to another view controller and retain the tab bar at the bottom of the segued to view.
我有一个应用程序,其中包含从选项卡栏控制器控制的多个视图控制器。从这些视图控制器中的一个我想(单击按钮)转至另一个视图控制器,并保留转至视图底部的选项卡栏。
I've used
我用过
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"newView"]){
UIViewController *controller =segue.destinationViewController;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
}
This works fine except the tab bar is missing from the segued to view (a placeholder shows for it in the storyboard, but it doesn't show up when the app is run) I've also tried replacing
这工作正常,除了 segued to view 中缺少标签栏(在故事板中显示了一个占位符,但在应用程序运行时它没有显示)我也试过替换
[self presentModalViewController:controller animated:YES];
with
和
[self presentViewController:controller animated:YES completion:nil];
but that doesn't work either.
但这也不起作用。
A bit of debugging shows that for the segued-to view controller, the tabBarController property is set to nil.
一些调试表明,对于 segued-to 视图控制器,tabBarController 属性设置为 nil。
Is there anyway to retain the tab bar in the segued-to view controller?
无论如何要在 segued-to 视图控制器中保留标签栏?
采纳答案by Gobot
From your explanation, I don't think you want a modal controller. Modal is used to overlay, rendering your tab bar useless. From your storyboard, select your segue and select push, not modal.
根据您的解释,我认为您不需要模态控制器。模态用于覆盖,使您的标签栏无用。从您的故事板中,选择您的转场并选择推送,而不是模态。
Push vs Modal (Note the tab bar):
Push vs Modal(注意标签栏):