简体   繁体   English

从UITabBarController选项卡根视图中显示UINavigationController

[英]Present UINavigationController from UITabBarController tab root view

I'd like to present a navigation controller from a tab bar controller's tab's root view controller and have the tabs from the tab bar controller visible. 我想从标签栏控制器的选项卡的根视图控制器中显示导航控制器,并使标签栏控制器中的选项卡可见。

Here's a photo of an example storyboard: 这是一个示例故事板的照片: 在此输入图像描述

The tab bar controller has a relationship to the ItemOneViewController , which is implemented like this: 标签栏控制器与ItemOneViewController有关系,它实现如下:

import UIKit

class ItemOneViewController: UIViewController {

  private func presentNavigationController() {

    let id = "NavController"
    guard let vc = storyboard?.instantiateViewController(withIdentifier: id) else { return }

    present(vc, animated: true)
  }

  override func viewDidAppear(_ animated: Bool) {

    super.viewDidAppear(animated)
    presentNavigationController()
  }
}

I hoped that by presenting the navigation controller from the root view controller of a tab on a tab bar controller that the navigation controller would be presented behind the tabs, but when I run the described app, this is what the simulator looks like: 我希望通过从标签栏控制器上的选项卡的根视图控制器呈现导航控制器,导航控制器将显示在选项卡后面,但是当我运行所描述的应用程序时,这就是模拟器的样子:

在此输入图像描述

This is what the view hierarchy looks like: 这是视图层次结构的样子:

在此输入图像描述

I think I remember a previous colleague mentioning that a UINavigationController will replace the view stack, which makes sense but is there anyway to keep it or bring the UITabBarController with it? 我想我记得前一位同事提到UINavigationController将替换视图堆栈,这是有道理的,但无论如何要保留它或带UITabBarController吗?

I've tried adjusting the presentation style and context but haven't had any luck. 我试过调整演示风格和背景但没有运气。

尝试在导航控制器中嵌入ItemOneViewController,而不是在导航控制器中嵌入ViewController VC。

Select ItemOneViewController from storyboard. 从故事板中选择ItemOneViewController

Go to the Editor and Embed with Navigation Controller 转到编辑器并使用导航控制器嵌入

在此输入图像描述

Your view hierarchy at Storyboard looks Like this : Storyboard中的视图层次结构如下所示:

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UITabBarController内部呈现UINavigationController - Present UINavigationController from inside UITabBarController 在UITabBarController和UINavigationController中以编程方式显示视图 - Present View within UITabBarController & UINavigationController Programmatically 来自UITabBarController的当前视图控制器,未显示选项卡栏 - Present view controller from UITabBarController without tab bar showing 以UITabBarController为根的Init UINavigationController - Init UINavigationController with UITabBarController as root 使用UITabbarController和UINavigationController从情节提要中调用View - Call View from storyboard with UITabbarController and UINavigationController 来自UITabBarController的当前模态视图 - Present Modal View from UITabBarController 从 UINavigationController 推送 UITabBarController - Push UITabBarController from UINavigationController 具有UINavigationController的UITabBarController,在hidesBottomBarWhenPushed而不是UITabBarController选项卡栏上隐藏UINavigationController工具栏 - UITabBarController with UINavigationController, hide UINavigationController toolbar on hidesBottomBarWhenPushed, not UITabBarController tab bar 使用UINavigationController在UITabbarController中不显示完整视图 - Not Displaying Complete View in UITabbarController with UINavigationController 问题推送视图,UITabBarController和UINavigationController - Problems push of view, UITabBarController and UINavigationController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM