Updating a global variable from JSON response inside function

前端 未结 2 1266
我在风中等你
我在风中等你 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条回答
  • 2021-01-29 09:07

    write this in your address function after fetching the data into your arrays

    DispatchQueue.main.async{
        tableView.reloadData()
       }
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题