Arrays 将数组从AppDelegate传递到视图控制器
我正在从AppDelegate中的Firebase数据库加载一个数组,因为我需要在创建和加载视图之前加载数组。如何将此数组传递给视图控制器以填充TableView 编辑: 我认为我的问题措辞不正确,也没有提供足够的信息。我有需要加载到数组中的Firebase数据。使用该阵列的视图控制器使用该阵列之前,需要将其加载到应用程序中。这是因为视图控制器使用cocoa pod将阵列拆分为多个类别,以在不同的TableView中显示。我正在使用的可可荚的回购协议可以找到Arrays 将数组从AppDelegate传递到视图控制器,arrays,swift,appdelegate,Arrays,Swift,Appdelegate,我正在从AppDelegate中的Firebase数据库加载一个数组,因为我需要在创建和加载视图之前加载数组。如何将此数组传递给视图控制器以填充TableView 编辑: 我认为我的问题措辞不正确,也没有提供足够的信息。我有需要加载到数组中的Firebase数据。使用该阵列的视图控制器使用该阵列之前,需要将其加载到应用程序中。这是因为视图控制器使用cocoa pod将阵列拆分为多个类别,以在不同的TableView中显示。我正在使用的可可荚的回购协议可以找到 那么,我的问题是,加载此阵列的最佳位
那么,我的问题是,加载此阵列的最佳位置是哪里?我的第一个想法是AppDelegate,但是数组是空的,因此表视图不会加载。我对iOS编程相当陌生,所以我愿意接受任何建议 在
AppDelegate
类中:
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
//Fill your array, let's say it's called firebaseArray. I would recommend doing so in the view controller and not in the Appdelegate for better responsibility distribution in your code
let vc = YourViewController()
//And YourViewController must have a array property
vc.array = firebaseArray
window = UIWindow(frame: UIScreen.main.bounds)
//make your vc the root view view controller
window?.rootViewController = vc
window?.makeKeyAndVisible()
return true
}
到目前为止,你尝试了什么?为什么不从根视图控制器加载数据?