在 Swift Playgrounds for iPad 中显示 TableView [英] Show TableView in Swift Playgrounds for iPad

查看:32
本文介绍了在 Swift Playgrounds for iPad 中显示 TableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切正常,除了我尝试在实时视图中显示 tableView 的最后一行不起作用:PlaygroundPage.current.liveView = controller

Everything works fine except the last line where I try to show the tableView in live view does not work: PlaygroundPage.current.liveView = controller

我不知道我做错了什么?

I can't figure out what I'm getting wrong?

import UIKit
import PlaygroundSupport
import Foundation

class TableViewController: UITableViewController {
    let tableData = ["Matthew", "Mark", "Luke", "John"]

override func viewDidLoad() {
    super.viewDidLoad()
    print("Hello Matt")
}

override func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tableData.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
    cell.textLabel?.text = tableData[indexPath.row]
    return cell
}
}

let controller = TableViewController()
PlaygroundPage.current.liveView = controller

推荐答案

我想你忘记在 viewDidLoad()

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

这篇关于在 Swift Playgrounds for iPad 中显示 TableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆