gpt4 book ai didi

swift - 重新加载数据后的 TableView 白色单元格

转载 作者:行者123 更新时间:2023-11-30 10:53:41 25 4
gpt4 key购买 nike

从 Firebase 加载数据后遇到问题,当我调用重新加载数据时, TableView 会填充新的列表数据,但都是白色的,如果我单击,我可以正确获取数据值。如果我使用静态数据一切正常。有什么建议吗?谢谢!

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

最佳答案

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
}

关于swift - 重新加载数据后的 TableView 白色单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54187985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com