。
目前我的相關代碼是什么?
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。///關鍵行。
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) {
像?.isUserInteractionEnabled = true
}
return cell
}
return UITableViewCell()
}
我嘗試了什么:
在準備重用時,我嘗試了lblName.text = "" 和 lblName.text = nil 沒有成功。
我還在cellForRowAt中嘗試了一下:
cell.lblName.text = nil
if cell.lblName.text == nil{
cell.lblName.text = person.Education。
}
我也試圖通過約束條件來完成,但沒有成功。
我認為可能的原因是什么
在我從TableViewController場景切換到ViewController(有輸出表)場景之前,這種情況并沒有發生。在我將單元格設定為不同的顏色之前,也沒有發生這種情況。
uj5u.com熱心網友回復:
我通過在label2上檢查清晰的圖形背景關系來使它作業。
uj5u.com熱心網友回復:
我認為你的問題可以通過檢查 label2 的 clear graphics context 來解決。
我認為如果你檢查單元格的高度,你的問題就會解決。 Check heightForCellAtRow Func
CodePudding
我還沒有看到你的單元格類。這個問題發生在你有約束問題的時候。因為自動布局系統無法計算行的高度,高度變成了0,從這一點開始的任何變化都可能是錯誤的。我建議你檢查單元格代碼,將標簽添加到contentView(如果它們不是),并在它們之間添加約束條件:
例如:
bottomLabel.topAnchor.constraint(equalTo: topLabel.bottomAnchor, constant: 8).isActive = true
同時將兩個標簽的壓縮阻力設定為.defaultHigh,如果你有硬編碼的行的高度,則將其洗掉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/311718.html
標籤:
