【问题标题】:How within a tab bar controller do I segue from one view controller to another and retain the tab bar?如何在标签栏控制器中从一个视图控制器切换到另一个并保留标签栏?
【发布时间】:2012-03-30 11:38:20
【问题描述】:

我有一个应用程序,其中有几个由标签栏控制器控制的视图控制器。从其中一个视图控制器中,我想(在单击按钮时)连接到另一个视图控制器,并将标签栏保留在被连接的底部以查看。

我用过

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"newView"]){
        UIViewController *controller =segue.destinationViewController;
        controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentModalViewController:controller animated:YES];
    }
 }

这工作正常,除了标签栏从 segued 中丢失(在情节提要中显示一个占位符,但在应用程序运行时不显示) 我也试过替换

[self presentModalViewController:controller animated:YES];

[self presentViewController:controller animated:YES completion:nil];

但这也不起作用。

一点调试表明,对于 segued-to 视图控制器,tabBarController 属性设置为 nil。

有没有办法在 segued-to 视图控制器中保留标签栏?

【问题讨论】:

    标签: ios xcode uistoryboard


    【解决方案1】:

    根据您的解释,我认为您不需要模态控制器。模态用于覆盖,使您的标签栏无用。从您的故事板中,选择您的 segue 并选择 push,而不是 modal。

    Push vs Modal(注意标签栏):

    【讨论】:

    • 我使用的是推送而不是模态。标签栏显示在情节提要中,但在应用程序运行时实际上并未出现
    • 要从代码使用[self performSegueWithIdentifier:@"theSegueIdentifier" sender:selfOrSomeObject] 启动segue,这是UIViewController 的一种方法。此行 controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController:controller animated:YES]; 用于 modal 转换而不是推送。删除此行。
    • 同样来自 Apple docs for presentModalViewController:animated..."在 iPhone 和 iPod touch 设备上,modalViewController 的视图始终全屏显示。在 iPad 上,显示取决于 modalPresentationStyle 属性中的值.
    • 我已按照您的建议开始使用代码,直到插入额外的行才能使 segue 工作。我现在发现 push segues 只能在 Navigation 控制器中工作(并且可以让它工作)。我认为导航控制器会出现问题,但我找到了“栏可见性复选框”,我正在使用 [self.navigationController popViewControllerAnimated:NO]; 关闭视图。感谢您的帮助,尤其是我读过但忘记的文档引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    相关资源
    最近更新 更多