0

双文本标签的屏幕截图

标签的当前约束

完整的层次结构

我目前的相关代码是什么

 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(带有输出表)场景之前,这并没有发生。

在我将单元格设置为不同颜色之前,它也没有发生。

4

3 回答 3

0

我通过检查 label2 上的清晰图形上下文来使其工作。

于 2021-08-30T08:25:41.190 回答
-1

我认为如果你检查单元格高度,你的问题会解决,检查 heightForCellAtRow Func

于 2021-08-25T15:05:10.310 回答
-1

我在你的牢房课上没见过。当您遇到约束问题时,就会发生该问题。由于自动布局系统无法计算行的高度,因此高度变为 0,从该点开始的任何更改都可能是错误的。

我建议您检查单元格代码,将标签添加到 contentView(如果不是)并在它们之间添加约束:

例如:

bottomLabel.topAnchor.constraint(equalTo: topLabel.bottomAnchor, constant: 8).isActive = true

还将两个标签的压缩阻力设置为 .defaultHigh ,如果您有硬编码的行的高度,请将其删除。

于 2021-08-25T15:11:02.047 回答