Я пытаюсь заполнить изображение в ячейку, но по какой-то причине он загружается в другие ячейки, когда это не должно.
Я не уверен, что бы это вызвало.
Я не уверен, но когда я прокручиваю вниз очень быстро было бы загрузить во все imageviews, когда он не хотел бы так:parsequery устанавливает одно изображение для всех uitableviewcells
Есть ли причина для этого?
Я также могу попытаться скрыть изображение, как только оно исчезнет,
, но пока я буду заниматься загрузкой изображения там, где он не должен.
Parsequery:
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()
}
}
}
TableView:
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
}
Update:
я добавил скрытый элемент следующим образом:
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
}
}
Теперь все изображения ушли :
Это сработало! Благодаря! –
на самом деле еще не повезло –