您好我想使用uiviewController上的按钮选择带有一些数据的tabbar项目,我可以使用此移动到另一个tabbar但是在这种方法中我无法移动数据
let second = self.tabBarController?.viewControllers?[2] as? MyAccountViewController
second?.testValue = "Test Value"
self.tabBarController?.selectedIndex = 2
崩溃报告
无法将'UINavigationController'类型的值(0x2496e5280)转换为'xxxxxx.MyAccountViewController'(0x1016cd4c8)。 2019-03-09 08:07:34.281652 + 0500 xxxxx [390:17926]无法将'UINavigationController'类型的值(0x2496e5280)转换为'xxxxxx.MyAccountViewController'(0x1016cd4c8)。
你需要验证它是vc with
let nav = self.tabBarController!.viewControllers![2] as! UINavigationController
let second = nav.viewControllers!.first as! MyAccountViewController
second.testValue = "Test Value"
self.tabBarController?.selectedIndex = 2
如果目标vc未激活(第一次打开),则打印qazxsw poi中的值如果它处于活动状态,则将其打印在qazxsw poi / qazxsw poi中