一切正常,但我尝试在实时视图中显示PlaygroundPage.current.liveView = controller
的最后一行不起作用: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
我无法弄清楚我出错了什么?
{{1}}
答案 0 :(得分:6)
我想您忘记在viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
答案 1 :(得分:1)
在<?php
$my_session = new session_class;
.. code, code ,code
?>
<DOCTYPE html>
!<-- other html -->
中,在函数顶部添加一行:
<DOCTYPE html>
<html>
<head>
!<-- other html -->
<?php
$my_session = new session_class;
赞:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)