首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >reloadData后TableView白色单元格

reloadData后TableView白色单元格
EN

Stack Overflow用户
提问于 2019-01-15 03:31:16
回答 1查看 86关注 0票数 0

从firebase加载数据后,我遇到了一个问题,当我调用reload data时,表视图填充了新的列表数据,但都是白色的,如果我单击它,我可以正确地获取数据值。如果我使用静态数据,一切都可以正常工作。有什么建议吗?谢谢!

代码语言:javascript
复制
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
    }

EN

Stack Overflow用户

发布于 2019-01-15 19:47:09

代码语言:javascript
复制
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
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54187985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档