I have a async function within functional tableview. I want to use the result of the function in my cell textlabel. But I don't know how to wait until the async function is finisched
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "groupDetail", for: indexPath)
let group = trainingGroups[indexPath.row]
cell.textLabel?.text = group.name
self.getTrainerByID(trainerId: group.trainer_id_main, completion: { [self] (isRead, err, trainer) in
if isRead {
cell.detailTextLabel?.text = trainer
trainerMain = trainer!
}else {
cell.detailTextLabel?.text = "Onbekend"
cell.detailTextLabel?.text = group.trainer_id_main
cell.layer.masksToBounds = true
cell.layer.borderWidth = 0.25
cell.layer.shadowOffset = CGSize(width: -1, height: 1)
let borderColor: UIColor = UIColor(red: 0, green: 45/255, blue: 114/255, alpha: 1)
cell.layer.borderColor = borderColor.cgColor
cell.accessoryType = .disclosureIndicator
cell.tintColor = UIColor.white
return cell
}
How do I make te return of te cell wait until the getTrainerByID is finished?
Best regards,
Armand