gpt4 book ai didi

ios - parsequery 正在为所有 uitableviewcells 设置一个图像

转载 作者:行者123 更新时间:2023-11-28 06:32:36 25 4
gpt4 key购买 nike

我正在尝试将图像填充到一个单元格中,但由于某种原因,它在不应该加载到其他单元格中。
我不确定是什么原因导致的。
我不确定,但是当我快速向下滚动时它会加载在不应该这样的时候进入所有 ImageView :

enter image description here

这有什么原因吗?
我也可能会在 ImageView 消失后尝试隐藏它,
但现在我会关心图像加载到它不应该加载的地方。

解析查询:

func getLocalComments(point:PFGeoPoint){
var temp = [CommentDetails]()
DispatchQueue.global(qos: .background).async {
let qComments = PFQuery(className: "UserCommentary")
let qDrinks = PFQuery(className: "venueDrinks")
if self.type == "House Parties"{
//Query the bars
qDrinks.whereKey("venueName", equalTo: self.id)
qDrinks.whereKey("venueID", equalTo: self.venueName)
qDrinks.addDescendingOrder("createdAt")

qComments.whereKey("venueID", equalTo: self.id)
qComments.whereKey("venueName", equalTo: self.venueName)

do{

let qReply1 = try qDrinks.findObjects()
if qReply1.count>0{
let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0)
var i = 0
while i < 2 {
let item = qReply1[i]
print(item)
comment.cellType = 2
i+=1
}
//temp.append(comment)
}
let qReply2 = try qComments.findObjects()
for item in qReply2{
let comment:CommentDetails = CommentDetails.init(comm: "Test", ven: self.venueName, venId: self.id, owner: PFUser.current()!.username!, vote: 0)
comment.commentOwner = item.object(forKey: "owner") as! String
comment.comment = item.object(forKey: "comment") as! String
comment.isFile = item.object(forKey: "image") as! Bool

if comment.isFile {
let dataPhoto:PFFile = item.object(forKey: "imgFile") as! PFFile
let imageData:NSData = try dataPhoto.getData()
let image:UIImage = UIImage(data:imageData as Data)!
comment.imageFile = image
comment.cellType = 2
}
temp.append(comment)
}
}
catch{
print(error)
}
}

DispatchQueue.main.async {
print(temp)
self.commentList.removeAll()
self.commentList = temp
self.commentTableView.reloadData()

}

}


}

表格 View :

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell{
var cell:commentTableViewCell
if commentList[indexPath.row].cellType == 1{
//drink
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "drink",for: indexPath) as! commentTableViewCell
cell.drinkName.text = commentList[indexPath.row].commentOwner
cell.drinkPrice.text = commentList[indexPath.row].comment
return cell
}
else{
//comment
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "comment",for: indexPath) as! commentTableViewCell
cell.ownerTitle.text = commentList[indexPath.row].commentOwner
cell.commentContent.text = commentList[indexPath.row].comment
if commentList[indexPath.row].isFile{
cell.imageView!.image = commentList[indexPath.row].imageFile
}
return cell
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return commentList.count
}

更新:

我添加了一个隐藏元素如下:

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell{
var cell:commentTableViewCell
if commentList[indexPath.row].cellType == 1{
//drink
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "drink",for: indexPath) as! commentTableViewCell
cell.drinkName.text = commentList[indexPath.row].commentOwner
cell.drinkPrice.text = commentList[indexPath.row].comment
return cell
}
else{
//comment
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "comment",for: indexPath) as! commentTableViewCell
cell.ownerTitle.text = commentList[indexPath.row].commentOwner
cell.commentContent.text = commentList[indexPath.row].comment
if commentList[indexPath.row].isFile{
cell.imageView!.image = commentList[indexPath.row].imageFile
}
else{

cell.imageView!.isHidden = true
}
return cell
}
}

现在所有图像都消失了:

enter image description here

最佳答案

if commentList[indexPath.row].cellType == 1 索引中使用 cell.imageView!.image = nil。试试这个

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell{
var cell:commentTableViewCell
if commentList[indexPath.row].cellType == 1{
//drink
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "drink",for: indexPath) as! commentTableViewCell
cell.drinkName.text = commentList[indexPath.row].commentOwner
cell.drinkPrice.text = commentList[indexPath.row].comment
cell.imageView!.image = nil
return cell
}
else{
//comment
cell = self.commentTableView.dequeueReusableCell(withIdentifier: "comment",for: indexPath) as! commentTableViewCell
cell.ownerTitle.text = commentList[indexPath.row].commentOwner
cell.commentContent.text = commentList[indexPath.row].comment
if commentList[indexPath.row].isFile{
cell.imageView!.image = commentList[indexPath.row].imageFile
}
return cell
}
}

关于ios - parsequery 正在为所有 uitableviewcells 设置一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928673/

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