我目前的相关代码是什么
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? ViewControllerTableViewCell {
let immy = cell.viewWithTag(1) as? UIImageView
let person: Userx = people[indexPath.row]
let text = person.Education
cell.lblName.text = person.Education. ///key line
cell.lblName.text = text?.uppercased()
cell.lblName?.layer.masksToBounds = true
let person5 = colorArray[indexPath.row]
let person6 = colorArray1[indexPath.row]
let person7 = colorArray2[indexPath.row]
let like = cell.viewWithTag(3) as? UIButton
cell.backgroundColor = person5
like?.backgroundColor = person6
immy?.backgroundColor = person7
cell.lblName.baselineAdjustment = .alignCenters
cell.postID = self.people[indexPath.row].postID
cell.row = indexPath.row
cell.delegate = self
cell.delegate2 = self
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
like?.isUserInteractionEnabled = true
}
return cell
}
return UITableViewCell()
}
我尝试了什么:
在准备重用时,我尝试lblName.text = "" and lblName.text = nil
了没有工作。
我也在 cellForRowAt 中尝试过:
cell.lblName.text = nil
if cell.lblName.text == nil{
cell.lblName.text = person.Education
}
我也试图通过约束来完成它,但没有运气。
我认为可能是原因
在我从 TableViewController 场景更改为 ViewController(带有输出表)场景之前,这并没有发生。
在我将单元格设置为不同颜色之前,它也没有发生。