gpt4 book ai didi

ios - 表格 View 单元格标签在滚动后发生变化并且其中的值错误如何解决?

转载 作者:行者123 更新时间:2023-11-28 19:31:04 24 4
gpt4 key购买 nike

每次我向上或向下滚动时,值都会在第一次更改为错误的值时显示正确的值,但在滚动后每次都会更改。

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
//creating a cell using the custom class
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ShowPercentageAttandanceTableViewCell




cell.rollNo.text = String(describing: self.mainArrayRoll[indexPath.row])


var location = Int()

for item in self.rollPercentage {
if item.rollCall == indexPath.row {
location = item.absentCount
cell.percentage.text=String(location)
}

else if cell.percentage.text==("Label")
{

cell.percentage.text=String("0")
}

}


return cell
}

这是代码。

[![这里,图 2 中的标签文本 =2,灰色标签文本 0,但滚动后会自动发生变化,如图 2[![图像 2 标签在滚动后发生变化,但它显示错误][2]][2]

enter image description here

最佳答案

当您没有找到您正在寻找的值时,您未能将 cell.percentage.text 设置为 "0"并且 你有一个重复使用的单元格。

试试这个:

if let item = self.rollPercentage.first(where: { $0.rollCall == indexPath.row }) {
location = item.absentCount
cell.percentage.text = String(location)
} else {
cell.percentage.text = "0"
}

关于ios - 表格 View 单元格标签在滚动后发生变化并且其中的值错误如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44746409/

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