使用按钮移动到包含数据的TabBar项目

问题描述 投票:0回答:1

您好我想使用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)。

ios swift uitabbarcontroller uitabbar
1个回答
0
投票

你需要验证它是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中

© www.soinside.com 2019 - 2024. All rights reserved.