0

既然 Swift 2 已经发布,我正在尝试再次编译我的应用程序,问题是我的TabBarController实例有错误。

我在 vars 中声明实例以便使用其他人的方法ViewControllers

这是我的代码:

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

在第二行我有以下错误:

UIViewController does not have a member named "viewControllers"

任何人都可以帮助我吗?

谢谢

4

1 回答 1

1

您正在尝试访问它没有viewControllers的 type的属性。是 a 的属性,但返回 的数组。UIViewControllerviewControllersUITabBarControllerviewControllersUIViewController

转换viewControllers为一组UITabBarController(或仅您提取的项目)以访问它的viewController属性。

像这样:

let barViewControllers = self.tabBarController?.viewControllers as! [UITabBarController]

或这个:

let listViewController = (barViewControllers![2] as! UITabBarController).viewControllers![0] as! dbViewController
于 2015-06-16T23:44:34.943 回答