Swift3:自定义单元格不显示数据

Swift 3: Custom Cell not displaying data

我从 php 收到一个 JSON 数组,并试图将数据传递到 table 视图。但是,我的tableview没有显示数据。

class test1ViewController: UIViewController  , UITableViewDataSource, UITableViewDelegate {


var TableData:Array< String > = Array < String >()



public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{

    return TableData.count

}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{


    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! testTableViewCell

    cell.mylabel1.text = TableData[indexPath.row]
    return cell

}

 func get_data_from_url(_ link:String)
{
    let url:URL = URL(string: link)!
    let session = URLSession.shared

    let request = NSMutableURLRequest(url: url)
    request.httpMethod = "GET"
    request.cachePolicy = NSURLRequest.CachePolicy.reloadIgnoringCacheData


    let task = session.dataTask(with: request as URLRequest, completionHandler: {
        (
        data, response, error) in

        guard let _:Data = data, let _:URLResponse = response  , error == nil else {

            return
        }

        print(data!)
        self.extract_json(data!)


    })

    task.resume()

}

func extract_json(_ data: Data)
{


    let json: Any?

    do
    {
        json = try JSONSerialization.jsonObject(with: data, options: [])
      //  print(json!)

    }
    catch
    {
        return
    }

    guard let data_list = json as? NSArray  else
    {
        return


    }

    if let countries_list = json as? NSArray
    {
        for i in 0 ..< data_list.count
        {
            if let country_obj = countries_list[i] as? NSDictionary
            {

                if let name = country_obj["name"] as? String
                {
                    if let age = country_obj["age"] as? String
                    {
                        TableData.append(name + age)




                    }
                }
            }
        }
    }




}

当数组给出初始值时 动物 = ["hinno", "ali", "khalil"], 这些值出现在自定义单元格中,但是当我从服务器获取数据并进行 json 转换时,什么也没有出现。

tableview.reloadData() 任何时候对数组进行更改。

如果重新加载集合或 tableView 的数据不起作用,请像这样在 Dispatch 代码中使用它

DispatchQueue.main.async {
         yourTableViewName.reloadData()
}