I am trying to Compile my app again now that Swift 2 is out and the thing is I am having an error with TabBarController
instances.
I am declaring the instances in vars in order to use methods from anothers ViewControllers
.
Here it's my code:
let barViewControllers = self.tabBarController?.viewControllers
let listViewController = barViewControllers![2].viewControllers![0] as! dbViewController //The [2] is because it's the third TabBar and the [0] it's because It's embebed in a NavigationController.
let calendarViewController = barViewControllers![1] as! CalendarViewController
In the second line Im having the following error:
UIViewController does not have a member named "viewControllers"
Anybody could help me?
Thanks
You are trying to access the property viewControllers
of the type UIViewController
, which it doesn't have. viewControllers
is a property on a UITabBarController
, but viewControllers
returns an array of UIViewController
.
Cast viewControllers
to an array of UITabBarController
(or only the item you extract) to access it's viewController
property.
Like this:
let barViewControllers = self.tabBarController?.viewControllers as! [UITabBarController]
Or this:
let listViewController = (barViewControllers![2] as! UITabBarController).viewControllers![0] as! dbViewController