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 typeUIViewController
, which it doesn't have.viewControllers
is a property on aUITabBarController
, butviewControllers
returns an array ofUIViewController
.Cast
viewControllers
to an array ofUITabBarController
(or only the item you extract) to access it'sviewController
property.Like this:
Or this: