【发布时间】:2020-11-21 11:32:17
【问题描述】:
我的数据库中有 3 个项目,我在 viewDidLoad() 中调用 tableView.reloadData(),这些单元格是从 FireStore 数据库中检索的。但是即使在 cellForRowAt 中的 print(indexPath.row) 之前,数据库也会从数据库中返回 3 个项目。我有一个喜欢功能,每次我有超过 2 件物品时它都会中断,我怀疑是因为这个。速度慢的计算机会导致这个问题吗?
print(indexPath.row) 与 db 中的 3 个项目返回:
0 1 2 1 2
有 2 个项目:
0 1 1
//cellForRowAt
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! PostCell
let p = postList[indexPath.row]
print("\(indexPath.row)")
// print("\(p.postId)")
cell.recipeName.text = p.recipeName
profileDataManager.loadProfile(p.username){
user in
self.userList = user
for i in self.userList{
cell.userName.text = i.displayName
}
}
cell.CLHLabel.text = "\(p.likes) likes, 10 comments, \(p.healthy) users find this healthy"
cell.tagsLabel.text = "\(p.tagBudget), \(p.tagPrep), \(p.tagStyle)"
cell.postID = p.postId
cell.postItem = p
cell.delegate = self
let imageRef = Storage.storage().reference(withPath: p.postImage)
imageRef.getData(maxSize: 4 * 1024 * 1024) { [weak self] (data, error) in
if let error = error {
print("Error downloading image: \(error.localizedDescription)")
return
}
if let data = data {
cell.postImage.image = UIImage(data: data)
}
}
cell.loadCell()
return cell
}
//numberOfRowsInSection
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return postList.count
}
【问题讨论】:
-
我很乐意提供任何代码
-
您绝对应该在问题中提供任何代码,并解释什么不符合您的预期。
-
@DougStevenson 好的,我会添加一些相关代码
-
能不能显示numberOfSection和numberOfRowsInSection函数
-
@aiwiguna 抱歉回复晚了,会补充的
标签: ios swift firebase uitableview google-cloud-firestore