Ios 无法强制转换类型为';UIViewController';到另一个viewcontroller
试图在视图控制器之间传递数据,但不断出现错误:Ios 无法强制转换类型为';UIViewController';到另一个viewcontroller,ios,swift,storyboard,Ios,Swift,Storyboard,试图在视图控制器之间传递数据,但不断出现错误: Could not cast value of type 'UIViewController' (0x10b4e4ca8) to 'StockList.AllListsTableViewController' (0x106d963f0). 我已检查以确保为视图控制器设置了类,但它仍然不起作用。以下是我的代码: func application(_ application: UIApplication, didFinishLaunchingWith
Could not cast value of type 'UIViewController' (0x10b4e4ca8) to 'StockList.AllListsTableViewController' (0x106d963f0).
我已检查以确保为视图控制器设置了类,但它仍然不起作用。以下是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let navigationController = window!.rootViewController as! UITabBarController
let controller = navigationController.viewControllers![0] as! AllListsTableViewController
controller.dataModel = dataModel
return true
}
提前感谢首先确保从Identity Inspector(
AllListsTableViewController
)将类名设置为IB中的VC
第二次使用
let tab = window!.rootViewController as! UITabBarController
let navigation = tab.viewControllers![0] as! UINavigationController
let controller = navigation.viewControllers![0] as! AllListsTableViewController
controller.dataModel = dataModel