I'm working on a macOS project where I have a split view containing 2 other ViewControllers and I can't figure out how to access the ViewControllers from my primary window's ViewController.
this is the setup:
Basically what I'm trying to do is use the Button
in my ViewController
on the top-left to access the Label
in my SectionController
on the right, which is embedded in my split view.
Since I can't create an IBAction
or IBOutlet
for a control in a different ViewController, I can't figure out how to get these to be connected. My current workaround has been to have a property on my AppDelegate
and then access the main shared application delegate, but that feels hacky and won't scale. I'm completely lost as to how to proceed. I'm ok with using a function to pass data or whatever to the other ViewController(s).
I'm using Swift 4 with Xcode 9 (beta).
Any ideas?
Of course you can't create IBAction or IBOutlet for a control in a different ViewController!! But simply each view controller in the hierarchy has a reference for its child view controllers.
Method 1:
Method 2:
It may be better if you took a reference for each child controller in your "prepare for segue" method
ContainerViewController:
YourSplitViewController:
So you can access it like that in your container view controller: