Show TableView in Swift Playgrounds for iPad

跟風遠走 提交于 2019-12-06 02:42:25

I think you forgot to register the table view cell class in viewDidLoad()

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}

In func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath), add one line to the top of the function:

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

Like this:

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

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
    cell.textLabel?.text = tableData[indexPath.row]
    return cell

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!