Answer the question
In order to leave comments, you need to log in
How to wait for a network request to complete and only then execute the following code?
In didSelectRow, a request is sent to the server (using Alamofire), and the text for the cell comes in the response, but what needs to be done to wait for the response and only then perform the rendering of the cell?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) as? AMHistoryTableViewCell {
if let selectedPath = selectedPath {
if selectedPath.section == indexPath.section, selectedPath.row == indexPath.row {
self.selectedPath = nil
}
} else {
self.selectedPath = indexPath
let item = self.items[(self.tableView.indexPath(for: cell)?.row)!]
if item.show == true {
let model = ReceiptRequestModel()
model.transactionId = item.id
Net.shared.request(requestType: .his(type: .receipt), model: model, completionHandler: {(error, json) in
if error == nil, let json = json {
if let resultModel = Mapper<ReceiptResponseModel>().map(JSON: json) { cell.descLabel = resultModel.desc
}
}
})
}
}
toggleCell(cell, animated: true)
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question