I have a class
class List {
var name: String
init(name: String) {
self.name = name
}
}
which is used to make the array. I declared the array
var providersList = [List]()
then used the function
func downloadData() {
db.collection("\(finalSelection.lowercased())_providers").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
self.providersList.append(List(name: "\(document.documentID)"))
}
}
}
}
to download the data. The data downloads correctly because there is no error and I also used print() to confirm the data is correct. However, when I use the functions for tableview
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MoreCell", for: indexPath) as! MoreInfoTableViewCell
cell.moreInfoLabel.text = providersList[indexPath.row].name
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return providersList.count
}
the table view isn't populated. I know this method works because I have used something similar to it in another area of my code (not downloading the data but populating the table view)
Edit: I tried to remove the class and append to the array normally without using the .name from the class. However, this didn't do anything either
Ok, so I found out the solution to this when I was laying in bed about to sleep (lol). In the function downloadData(), I have to put self.tableView.reloadData() after appending to the array. I will include this for anyone who faced a similar problem like me.
func downloadData() {
db.collection("\(finalSelection.lowercased())_providers").getDocuments() { (querySnapshot, err) in
if let err = err {
print("Error getting documents: \(err)")
} else {
for document in querySnapshot!.documents {
self.providersList.append(List(name: "\(document.documentID)"))
self.tableView.reloadData()
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With