简体   繁体   English

当添加两个以上相同单元格时,图像无法很好地显示(动态tableView)

[英]Image not display well when added more than 2 same cells (dynamic tableView)

With my system I build my cell programmatically and set what I need in the cell compared to my array (data source of my tableView). 使用我的系统,我可以通过编程方式构建单元格,并与数组(tableView的数据源)相比,设置单元格中所需的内容。

The problem appear when i add 3 cells or more on my tableView. 当我在tableView上添加3个或更多单元格时出现问题。 The text is good but the image does not appear in the correct cell. 文本很好,但是图像没有出现在正确的单元格中。 I think this is a problem of the cache of the TableView system (reuse). 我认为这是TableView系统缓存(重用)的问题。 I follow several post in this forum to fix that but nothing work. 我在该论坛上关注了几处帖子,以解决此问题,但没有任何效果。

This is my code in cellForRowAt : 这是我在cellForRowAt代码:

let waitingCell = tableView.dequeueReusableCell(withIdentifier:"waiting", for: indexPath) as! CardCellWaiting
var cellToReturn : UITableViewCell!
let currentSurvey = user.lobbySurvey[indexPath.row]
let state : UserSurvey.state = currentSurvey.stateSurvey
switch state{
case .surveyWaiting:
    cellToReturn = waitingCell
    waitingCell.drawCard() // draw the card programmatically if needed
    waitingCell.clearImage() // look below to see the function
    waitingCell.setId(id: currentSurvey.id)
    waitingCell.setImage(image : currentSurvey.picture)
    waitingCell.setTimeLeft(timeLeft: currentSurvey.timeLeft)
    waitingCell.delegate = self
    waitingCell.delegateCard = self
}
return cellToReturn

this is how I update my source data (lobbySurvey) an array who contain User Survey classes. 这就是我如何更新包含用户调查类的数组的源数据(lobbySurvey)。 I build my cells since this one. 从这开始,我开始建立自己的细胞。

user.lobbySurvey.remove(at: 0)
self.tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .fade)
let surveyWaiting = UserSurvey(stateOfSurvey: .surveyWaiting)
surveyWaiting.picture = image
if let url = json["imageUrl"].string {
    surveyWaiting.pictureUrl = url
}
if let timeLeft = json["timeLeft"].string {
    surveyWaiting.timeLeft = timeLeft
}
if let surveySelfId = json["surveySelfId"].string {
    surveyWaiting.id = Int(surveySelfId)
}
let rowToInsert = self.getRowToInsert(typeOfState: .surveyWaiting)
user.counterSurvey += 1
user.lobbySurvey.insert(surveyWaiting, at: rowToInsert)
self.tableView.insertRows(at: [IndexPath(row: rowToInsert, section: 0)], with: .fade)

this is the clearImage function : 这是clearImage函数:

func clearImage(){
    surveyWaiting.imageEmptyView.image = #imageLiteral(resourceName: "backgroundEmptyImage")
}

and my setImage function : 和我的setImage函数:

func setImage(image : UIImage){
    surveyWaiting.imageEmptyView.image = image.resized(targetSize: CGSize(width:100,height:125))
}

I've try to empty my imageView like : 我试图像这样清空我的imageView:

surveyWaiting.imageEmptyView.image = nil

But don't work. 但是不行。 I've also try to use a framework like Nuke with the url of the image, but nothing. 我还尝试使用像Nuke这样的框架来处理图像的网址,但一无所获。

Can anyone have an idea of why my code not order the image in the good cell ? 谁能想到为什么我的代码无法在优质单元格中对图像进行排序? Thanks to your reply. 多谢您的回覆。

好的,我的错误...我使用此框架在我的imageView上绘制异步模糊,但是此插件保留了具有模糊的图像的缓存。因此,我只删除了模糊的缓存即可解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加到表格单元格的按钮也出现在其他随机单元格上 - Button added to tableview cell appears on other random cells as well 添加了20多个tableviewcell,但之后无法滚动tableview以查看jonkykong / SideMenu iOS演示应用程序中的所有单元 - Added more than 20 tableviewcells but after that not able to scroll tableview to see all cells in jonkykong/SideMenu iOS demo application TableView中的更多单元格 - More cells in TableView 动态tableview单元格创建 - Dynamic tableview cells creation 如何实现一个包含另外 2 个单元格的表格视图单元格,计数不一样 - How to implement a tableview cell that contains 2 more cells inside counts are not same 如何在同一UITableViewVibrantCell中加载两个不同的动态tableview单元格 - how to load two different dynamic tableview cells in same UITableViewVibrantCell 不显示所有单元格的TableView - Not display all cells TableView ios Swift tableView 以编程方式查看标签和图像的动态单元格约束 - ios Swift tableView dynamic cells constraints for labels and image programatically 当用户滚动到表格视图框架的底部时,加载更多单元格 - Load more cells when user scrolls to bottom of tableview frame 如果未选择tableView单元格时按下按钮,则显示警报消息 - Display alert message if button is pressed when no tableView cells selected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM