I am new to iOS, How can I access child view controllers form UITabBarController
? Currently, I have the following.
The child view controllers are connected using a Relationship Segue
in the storyboard. I want to set some properties in child views from UITabBarController
. How this can be accomplished.
Storyboard
You might define the following enum for mapping your classes:
enum TabType:Int {
case RequestTabBarController
case ActiveRequestsTableViewController
case RequestViewController
}
In such way you can have a clean access to your viewControllers
:
An array of the root view controllers displayed by the tab bar interface.
which you can get directly from your UITabBarController
, doing so:
private weak var tabVc:UITabBarController?
var niceObject:Whatever?
//...//
override public func prepare(for segue: UIStoryboardSegue, sender: Any?) {
self.tabVc = segue.destination as? UITabBarController
if let vc = self.tabVc?.viewControllers?[TabType.RequestTabBarController.rawValue] as? RequestTabBarController {
vc.doWhatEver(niceObject)
}
}