tableView data source empty in viewDidLoad() - Swift

前端 未结 3 1137
北恋
北恋 2021-01-14 23:31

Below is my ViewController code. The println in GetRequest prints the correct data that it receives from the HTTP GET request. At this point, tableData has 10 key-value pair

3条回答
  •  醉梦人生
    2021-01-14 23:55

    Rearrange the orders of the method calls:

    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        var apiInfo = GetWaitTimes()
        GetRequest(apiInfo.BorderCrossingApi+"?AccessCode="+apiInfo.AccessCode)
        tableView.reloadData()
    }
    

    Explanation: you set the delegate and dataSource before you GetRequest() so the dataSource won't be nil.

提交回复
热议问题