Using Swift 4+, iOS 11.4+, Xcode 10+ (使用Swift 4 +,iOS 11.4 +,Xcode 10+)
I'm using a ContainerView with a Navigation controller to load multiple ViewControllers. (我正在使用带有导航控制器的ContainerView来加载多个ViewController。)
In addition, the ViewController that holds the ContainerView is also pushed onto a different NavigationController stack. (另外,保存ContainerView的ViewController也被推送到另一个NavigationController堆栈上。)
See this graphic: (看这个图:)
The "Menu" is the root controller in the stack. (“菜单”是堆栈中的根控制器。) I am pushing another ViewController (TopViewController) onto the same stack - so far so good. (我将另一个ViewController(TopViewController)推送到同一堆栈上-到目前为止一切顺利。)
My issue is that I want to "pre-load" the TopViewController > ContainerView with a different ViewController (Item1) before the TopViewController becomes visible. (我的问题是,我想在TopViewController变得可见之前 ,使用其他ViewController(Item1)“预加载” TopViewController> ContainerView。)
There are other ViewControllers in addition Item1 that I will need to "pre-load" in this manner. (除了Item1之外,还有其他ViewController我需要以这种方式“预加载”。)
I have tried using "viewDidLoad" in TopViewController to push Item1, (我尝试在TopViewController中使用“ viewDidLoad”来推送Item1,)
toVC = storyboard?.instantiateViewController(withIdentifier: "Item1") as! Item1
TopNav.pushViewController(toVC, animated: true)
and it works - but only after TopViewController becomes visible. (并且有效-但仅在To??pViewController可见之后。) This means that you can see Item1 "pop" into view rather than already being visible. (这意味着您可以在视图中看到Item1“弹出”,而不是已经可见。)
I have also tried this code from within the Menu VC, but it does not push anything onto the ContainerView. (我也从Menu VC中尝试过此代码,但它不会将任何内容推送到ContainerView上。)
let toVC = self.storyboard?.instantiateViewController(withIdentifier: "TopViewController") as! TopViewController
// Tried this to 'pre-load' the next VC - shows no VC, and disables 'back' navigation
let toNav = toVC.navigationController
let nextVC = storyboard?.instantiateViewController(withIdentifier: "Item1") as! Item1
// Neither of the lines below loads the Item1 VC....
//toNav?.viewControllers = [nextVC]
toNav.pushViewController(toVC, animated: true)
How can I push Item1 onto the Navigation stack for the ContainerView before the VC with the ContainerView becomes visible? (在带有ContainerView的VC可见之前,如何将Item1推送到ContainerView的导航堆栈上?)
FYI: You can download my sample project here: https://gitlab.com/whoit/newviews (仅供参考:您可以在此处下载我的示例项目: https : //gitlab.com/whoit/newviews)
ask by wayneh translate from so