我需要从 ViewController-B 读取 ViewController-A 中的数组,以便填充 ViewController-B 中的 UIPickerView 的数据。我该怎么做?
我试过这个答案:
https://stackoverflow.com/a/31574620/7127489
但我不知道为什么我不能像它所说的那样实例化我的 ViewController-B,以便将我的填充数组传递给另一个类中的空数组。
有什么想法吗? 非常感谢!
最佳答案
您可以使用委托(delegate)来传递数据(SO 上有许多委托(delegate)示例)或 here 或者你可以这样做:
如果在导航 Controller 中:
if let navController = self.tabBarController?.viewControllers?[1] as? UINavigationController, let yourController = navController.viewControllers[0] as? yourVC{
yourArray = yourController.array
}
如果不在navigationController中:
if let yourController = self.tabBarController?.viewControllers?[1] as? yourVC{
yourArray = yourController.array
}
关于ios - 从 Swift 中的其他类读取数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45434453/