Белая ячейка TableView после reloadData - PullRequest
0 голосов
/ 14 января 2019

У меня проблема после загрузки данных из firebase, когда я вызываю данные перезагрузки, табличное представление заполняется новыми данными списка, но все они белые, и если я нажму, я смогу правильно получить значение данных. Если я использую статические данные, все работает нормально. Любое предложение? спасибо!

private func loadUniversity(url: String) {

        let configuration = URLSessionConfiguration.ephemeral
        let session = URLSession(configuration: configuration)
        let url = URL(string: url)!

        let task = session.dataTask(with: url) {

            (data, response, error) in

            guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200, let data = data else {
                return
            }
            do {
                let decoder = JSONDecoder()
                let university = try decoder.decode([UniversityJSON].self, from: data)
                for item in university {
                    self.universityArray.append(University(name: item.university_name.trim()))
                }
                let queue = OperationQueue.main
                queue.addOperation {
                    self.currentUniversityArray = self.universityArray
                    print(self.currentUniversityArray)
                    self.table.reloadData()
                }
            } catch {
                print("Error info: \(error)")
            }
        }
        task.resume()
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? UniversityCell else {
            return UITableViewCell()
        }
        cell.name.text = currentUniversityArray[indexPath.row].name
        return cell
    }

enter image description here

1 Ответ

0 голосов
/ 15 января 2019
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? UniversityCell else {
      return UITableViewCell()
   }
   cell.name.text = currentUniversityArray[indexPath.row].name
   // Put this background Color
   cell.backgroundColor = .clear
   return cell
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...