I have a UIColelctionView cell that should contain users names located in a firebase database.
First I referenced the custom cell using:
let f = FriendCell()
In cellForItemAt indexPath, I define each cell and reference the array from which the data is coming from. Then I reference the individual user the particular cell will get its data from.
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: userResultCellId, for: indexPath) as! FriendCell
let user = users[indexPath.row]
f.nameLabel.text = user.name
print(f.nameLabel.text!)
return cell
}
When I run this, the console print(f.nameLabel.text!)
actually prints the user names correctly, however they don't seem to pass into the cell correctly.
What I believe is happening is each cell is getting set up before the data is downloaded and the namelabel is returning nil because there isn't a value there. But what's weird is that when I print the value it returns the names correctly. Any suggestions?