我正在使用来自AppDelegate中Firebase数据库的数据加载数组,因为我需要在创建和加载视图之前加载数组。如何将此数组传递给视图控制器以填充TableView?
编辑:我认为我没有正确地提出我的问题,也没有提供足够的信息。我有这个需要加载到数组中的Firebase数据。在使用该数组的视图控制器使用该数组之前,需要将该数组加载到应用程序中。这是因为视图控制器使用可可窗格将数组拆分为多个类别,以便在不同的视图中显示。我正在使用的可可豆荚回购可以找到here。
我的问题是加载这个数组的最佳位置在哪里?我的第一个想法是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
}