[英]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.