在我看來:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TransactionTableCell", for: indexPath) as! TransactionTableCell
let newItem = getTransactionsInSection(section: sectionHeader[indexPath.section])[indexPath.row]
cell.configure(item: newItem)
}
在我的 TransactionTableCell
func configure(item: TransactionModel) {
guard let withdrawalBonuses = item.withdrawalBonuses,
withdrawalBonuses < 0,
let accruedBonuses = item.accruedBonuses,
accruedBonuses > 0 else {
configureWithOneOperation(item)//shows one line of operation
return
}
//show 2 lines of operations
firstOperationAmountLabel.text = " \(Int(accruedBonuses))"
secondOperationAmountLabel.text = "\(Int(withdrawalBonuses))"
}
當我滾動單元格時,第二條操作線出現在不應該出現的錯誤單元格中,即使我重新加載表格,也會出現這個問題。
uj5u.com熱心網友回復:
您應該使用prepareForReuse()方法
只需清除標簽的資料:
override func prepareForReuse() {
super.prepareForReuse()
firstOperationAmountLabel.text = nil
secondOperationAmountLabel.text = nil
}
uj5u.com熱心網友回復:
這里有幾件事要檢查。
- 確保在配置新單元之前重置所有欄位。
- 如果您使用 xib 或情節提要創建了一個單元格,請確保您沒有使用靜態文本填充標簽。
- 你的守衛宣告是否通過了每一項?
- 用于保護的其他塊使用單個操作配置單元格,它是否處理單元格中的所有 ui 元素?
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/421117.html
標籤:
上一篇:查找兩個CGPoints之間的點
