我在 Tableview 单元格中有 collectionView。当我从 firebase 获取数据时,我将数据保存到数组中,然后尝试将其放在 Collection View 中。但是,即使我手动将数据放入数组中,我的 array.count 始终显示为零,并且我的 Collection View 中没有任何内容。
override func viewDidLoad() {
super.viewDidLoad()
currentuserArray.append(User(email: "x@gmail.com", image: "ASD"))
currentuserArray.append(User(email: "y@gmail.com", image: "ASD"))
print(currentuserArray.count)
tableView.delegate = self
tableView.dataSource = self
getDataFromFirebaseToTakeUsers()
}
在那里,currentuserArray.count 的值为 2。
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(currentuserArray.count)
return currentuserArray.count // this looks like 0, however at the top, it was 2.
}
但是;在那里,userMailArray.count 的值为 0。因此,我的 collectionView 上没有任何内容。怎么可能?
最佳答案
问题是getDataFromFirebaseToTakeUsers
是异步的,你需要
self.collectionView.reloadData()
内部完成
关于ios - 我在 Tableview 单元格中有 collectionView。它总是返回零。我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59707945/