Here is the layout of my app
I am trying to access a variable of startViewController from within TableViewController.
When I print the viewControllers of splitViewController (print(self.splitViewController?.viewControllers)
) from within tableViewController this is what I get
Optional([<UINavigationController: 0x12200f600>, <temp.CollectionViewController: 0x121e16860>])
That second viewController(temp.CollectionViewController
) should be of type startViewController.
The startViewController in my program presents the collectionViewController using a segue with kind show. The collectionViewController has already been segued to when I call print(self.splitViewController?.viewControllers)
.
I ended up needing to put StartViewController inside a UINavigationController. I was then able to access the first viewController with
var detailStart = (splitViewController?.viewControllers[1] as? UINavigationController)?.viewControllers.first as? StartViewController
I then hid the unwanted navigation bar with
navigationController?.setNavigationBarHidden(true, animated: false)
Which was placed inside viewDidAppear
This ended up being an ok solution for me, because I needed to put CollectionViewController inside a UINavigationController anyway, but it seems kind of hacky and maybe not the best practice