Ios UITableViewCell不显示数据-Swift游乐场

Ios UITableViewCell不显示数据-Swift游乐场,ios,swift,uitableview,swift-playground,custom-cell,Ios,Swift,Uitableview,Swift Playground,Custom Cell,我一直在尝试在swift playgrounds iPad应用程序的视图控制器中创建的表格视图中实现一些自定义单元格。请注意,我已经看到许多其他的堆栈溢出帖子处理类似的问题,但并没有找到解决方案来解决我的问题 这是我的CustomCell课程: class CustomCell: UITableViewCell { let projectImage = UIImageView() //let projectDivider = UIView() let projectTi

我一直在尝试在swift playgrounds iPad应用程序的视图控制器中创建的表格视图中实现一些自定义单元格。请注意,我已经看到许多其他的堆栈溢出帖子处理类似的问题,但并没有找到解决方案来解决我的问题

这是我的CustomCell课程:

class CustomCell: UITableViewCell {

    let projectImage = UIImageView()
    //let projectDivider = UIView()
    let projectTitle = UILabel()

    override func awakeFromNib() {
        projectImage.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
        //projectDivider.frame = CGRect(x: 100, y: 0, width: 20, height: 100)
        projectTitle.frame = CGRect(x: 120, y: 0, width: 200, height: 100)

        self.contentView.addSubview(projectImage)
        //self.contentView.addSubview(projectDivider)
        self.contentView.addSubview(projectTitle)
    }

}
以下是我的视图控制器代码:

class AboutViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    let tableView = UITableView()
    let cellReuseIdentifier: String = "cell"

    var projectTitles = ["Madhubani Coffee", "World Savvy", "Zipshare", "CrashThatCode", "Future Plans"]
    var images: [UIImage] = [UIImage(named: "IMG_0061.JPG")!, UIImage(named: "IMG_0064.JPG")!, UIImage(named: "IMG_0062.JPG")!, UIImage(named: "IMG_0062.JPG")!, UIImage(named: "IMG_0062.JPG")!]

    override func viewDidLoad() {
        view.backgroundColor = UIColor.white

        tableView.frame = CGRect(x: -82.5, y: 250, width: 600, height: 600)
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = UIColor.white

        self.tableView.register(CustomCell.self as AnyClass, forCellReuseIdentifier: cellReuseIdentifier)
        view.addSubview(tableView)

     }

     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        var cell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier, for: indexPath) as! CustomCell

        if cell == nil {
            cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellReuseIdentifier) as! CustomCell
        }

        cell.projectImage.image = images[indexPath.row]
        cell.projectTitle.text = projectTitles[indexPath.row]

        cell.clipsToBounds = true

        return cell
    }
}

我不知道是什么问题。这些细胞似乎根本不显示。任何帮助都将不胜感激

您的问题是您没有一个
nib
(或
xib
)文件来执行
awakeFromNib

请尝试为您的CustomCell执行以下操作:

class CustomCell: UITableViewCell {

    let projectImage = UIImageView()
    //let projectDivider = UIView()
    var projectTitle = UILabel()

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

        projectImage.frame = CGRect(x: 0, y: 0, width: 100, height: 30)
        //projectDivider.frame = CGRect(x: 100, y: 0, width: 20, height: 100)
        projectTitle.frame = CGRect(x: 10, y: 0, width: 200, height: 30)
        projectTitle.font = UIFont.systemFont(ofSize: 20.0)
        //self.contentView.addSubview(projectImage)
        //self.contentView.addSubview(projectDivider)
        self.contentView.addSubview(projectTitle)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}