【问题标题】:UIViewController containing a flow of UIViewControllersUIViewController 包含 UIViewControllers 流
【发布时间】:2016-07-08 07:30:08
【问题描述】:
我正在构建一个 UIViewController (outer viewController),其中包含另一个 UIViewController (inner viewController)。为此,我正在使用容器视图。现在我希望内部 viewController 推送到另一个 UIViewController,所以我基本上希望内部 viewController 成为 UINavigationController 的子级。我知道一旦初始化容器视图(无论如何都不是直接),您就无法更改容器视图的内容,所以我碰壁了。
有人对我如何将UINavigationController 嵌套在UIViewController 中有任何想法,还是我需要重新考虑解决问题的方法?
【问题讨论】:
标签:
ios
swift
uiviewcontroller
uinavigationcontroller
addsubview
【解决方案1】:
您只需发送UINavigationController。
用你的 InnerViewController 初始化它。
现在,在 OuterViewController 中将UINavigationController 添加为 (childViewController + addSubview + didMoveToParentViewController)。
现在,InnerViewController 位于 UINavigationController 内。您可以在UINavigationController 上推送任何您想要的内容。
【解决方案2】:
受到@7vikram7 的极大启发,我最终得到了一个嵌入了UINavigationController 的容器视图,其中我的InnerViewController 作为其根视图控制器:
在我的 InnerViewController 中,我现在可以推送到任何 UIViewController,并控制我的导航堆栈,例如:
override func viewDidLoad() {
super.viewDidLoad()
// Hide the navigation bar
self.navigationController?.setNavigationBarHidden(true, animated: false)
// Push to whatever viewController I want to
let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("myAwesomeViewController") as! AwesomeViewController
self.navigationController?.pushViewController(viewController, animated: true)
}