首页 > 解决方案 > UITableViewCells 没有正确创建?

问题描述

我正在使用 Storyboard 创建 UITableView,但是在创建自定义单元格时它没有正确创建。请参阅下面的屏幕

![在此处输入图像描述] 1

在此屏幕中,另一个以白色显示的新视图。这仅在 Swift 中发生。我清楚地检查了我的原型单元格中只有两个标签。没有第三种观点。

我的代码是

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    // create a new cell if needed or reuse an old one

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCellClass
    cell.permissionClassTitleLbl.text = titleArray[indexPath.row]
    cell.permissionClassDescLbl.text = descArray[indexPath.row]
    cell.permissionClassDescLbl.numberOfLines = 0

    //        cell.textLabel?.backgroundColor = UIColor.blue

    return cell

}

我的故事板 ViewController 屏幕是。

![在此处输入图像描述] 2

![在此处输入图像描述] 3

但是当我写cell.textLabel?.backgroundColor = UIColor.blue这个代码时,第三个视图消失了。为什么我不知道的原因。请参阅下面的屏幕

![在此处输入图像描述] 4

我在整个项目中为所有 TableViewCell 使用 Single TableViewCell 类。

标签: iosswiftuitableview

解决方案


推荐阅读