我正在尝试为我的应用程序实现菜单。我有 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/