ios - 在 TabBarController 中添加 View Controller 作为带有导航栏的 subview

标签 ios swift uinavigationcontroller uitabbarcontroller uinavigationbar

我有一个带有 4 个选项卡栏的选项卡栏 Controller 。我有子类选项卡栏 Controller ,并在选项卡栏 Controller 的 View 上添加了 UIView。 我想在 UIView 中添加一个 View Controller 作为 subview 或 subview Controller 。我已经做到了

let nvc : UIViewController = self.storyboard?.instantiateViewController(withIdentifier: "SongDetailVC") as! SongDetailsVC

nvc.willMove(toParentViewController: self)
playerMainView.addSubview(nvc.view)
self.addChildViewController(nvc)
nvc.didMove(toParentViewController: self)

但问题是,使用此代码我只能添加 SongDetailVC 的 View 。虽然我也想添加导航栏。

我尝试将 SongDetailVC 嵌入到导航 Controller 中。 我无法获得导航栏。

有什么办法可以实现这一点吗? ?

最佳答案

如果您的 SongDetailVC 嵌入到 UINavigationController 中,并且您也需要 UINavigationController,那么您将需要实例化 UINavigationController。确保在 Storyboard中设置标识符。

关于ios - 在 TabBarController 中添加 View Controller 作为带有导航栏的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50683422/

相关文章:

ios - NSMutable 字典无法正常工作

ios - 如何在 Swift 中获取 UIImage 中像素的颜色?

ios - 无法在导航栏中设置左栏按钮项?

ios - Swift - 预处理器宏和类声明

ios - InteractivePopGestureRecognizer 弹出太多 View

objective-c - 向 rightBarButtonItems 添加两个按钮不起作用

ios - 检测屏幕亮度调节是否设置为自动

ios - 如何通过 swift ios 中的键值读取子数据或过滤 firebase 数据

objective-c - 如何确保 UINavigationController 在弹出另一个动画之前已经完成动画?

ios - UIViewController 的 navigationController 属性