ios - 在 TabBarController 中到达 ViewController

标签 ios iphone swift uiviewcontroller swift3

我正在尝试为我的应用程序实现菜单。我有 TabBarViewController -> NavigationViewController -> ContentViewController。当应用程序启动时,我打开 HostViewController。在 HostViewController 内部,我必须使用这段代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
contentList.append(tabbarVC as MenuItemContentViewController)

但是MenuItemContentViewController只是继承了UIViewController。所以我不能将此代码与标签栏一起使用。

我试过了

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let contentVC = storyboard.instantiateViewController(withIdentifier: "ContentViewController") as! ContentViewController
contentList.append(contentVC as MenuItemContentViewController)

但是它添加了没有标签栏的contentViewController。

有谁知道如何添加带标签栏和导航栏的 contentViewController?

谢谢。

最佳答案

根据我的理解,您希望将 contentViewController 嵌入到带有导航栏的标签栏中。您需要在任何事件上将 subview 推送或添加到 hostViewController,即“IBAction 或按钮单击”

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
self.present(tabbarVC, animated: True){} //In HostViewController's Self

或者

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController 
self.view.addSubview(tabbarVC.view) //In HostViewController's Self

关于ios - 在 TabBarController 中到达 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42578326/

相关文章:

ios - 可以使 UIGestureRecognizer 在 AVPlayerViewController 中工作吗?

ios - Amazon sns(推送通知)不发送到 IOS 应用程序

iphone - 困难/特殊环境中的多语言 iApp

iphone - iPhone-如何使我的标签看起来像iPhone的内置标签?

iphone - SplitViewController 中的 UIPopoverController

ios - 清除按钮未显示在 UITextField 上

iphone - 核心数据 NSSet 返回空对象数组

iOS/核心数据实体与预定义数据的关系

ios - PredictHQ API 上的 "Bad Request"响应 [ "error": invalid_client] "authentication" request

arrays - 在 Xcode 10.2 中将数组读取和写入文本文件的代码