我目前正在尝试将我的Swift iOS应用程序转换为Swift 2.我已设法删除了编译器错误(在stackoverflow中提供了一些很好的帮助)但是我遇到了问题。应用程序一旦编译完毕。我的应用程序有一个带有3个选项卡的tabBarController。当我选择第二个标签时,应用程序现在崩溃了一个' SIGABRT'错误。
我收到错误:
无法转换类型的值' UINavigationController' (0x106fbd588)到' FlightTracker.MapViewController' (0x105722430)
以下代码:
let mapviewcontroller = self.tabBarController?.viewControllers?[0] as! MapViewController
为什么它不能将控制器转换为MapViewController?我在iOS 9&之前让它以这种方式工作斯威夫特2.
答案 0 :(得分:2)
应该有效
let navigationController = self.tabBarController?.viewControllers?[0] as! UINavigationController //Check which is your tab on your storyboard, 0, 1, n ?
let mapviewcontroller = navigationController.viewControllers[0] as! MapViewController
self.tabBarController?.viewControllers?[0] =>它是你的UINavigationController
在你的故事板上你的tabBarController连接到 N UINavigationController S ,你的一个UINavigationController连接到你的MapViewController。