Updating a global variable from JSON response inside function

前端 未结 2 1271
我在风中等你
我在风中等你 2021-01-29 08:39

I\'m trying to get some variables from JSON response and display it in a custom table view.. the problem is that the variables are never updated.. for more explanations here\'s

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 09:18

    1- Reload the table

    if let address = receivedTodo["address"] as? [[String:Any]] {
        for info in address {
          self.label.append(info["label"] as! String)
          //self.street.append(info["description"] as! String)
          //self.building.append(info["building_number"] as! String) 
       }
    }
    
    DispatchQueue.main.async {
       self.tableView.reloadData()
    }
    

    2- Verify by a print before reload as you may have a nil response

提交回复
热议问题