gpt4 book ai didi

ios - 添加超过 2 个相同的单元格(动态 tableView)时图像显示不佳

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

在我的系统中,我以编程方式构建我的单元格,并在单元格中设置我需要的内容与我的数组(我的 tableView 的数据源)进行比较。

当我在 tableView 上添加 3 个或更多单元格时出现问题。文本很好,但图像未出现在正确的单元格中。我认为这是TableView系统缓存的问题(复用)。我按照这个论坛中的几个帖子来解决这个问题,但没有任何效果。

这是我在 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

这就是我如何更新我的源数据 (lobbySurvey) 一个包含用户调查类的数组。我从这个细胞开始 build 我的细胞。

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)

这是 clearImage 函数:

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

和我的 setImage 函数:

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

我尝试像这样清空我的 imageView:

surveyWaiting.imageEmptyView.image = nil

但它不起作用。我也尝试使用像 Nuke 这样的框架带有图片的 url,但什么也没有。

为什么我的代码没有对正确单元格中的图像进行排序?

最佳答案

好吧,我错了……我用这个framework为我的 imageView 绘制异步模糊,但是这个插件保留了模糊图像的缓存。所以我只是删除了模糊的缓存,这解决了问题。

关于ios - 添加超过 2 个相同的单元格(动态 tableView)时图像显示不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53094911/

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