2016-09-25 33 views
2

,一切工作正常,除了最後一行,我試圖表明的tableView在實時取景不起作用:PlaygroundPage.current.liveView = controller顯示的TableView爲iPad

我想不出什麼我越來越錯了嗎?

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 
+0

登記表視圖細胞類什麼不起作用?有錯誤嗎?怎麼了? –

+0

@JackLawrence akosma釘了它,欣賞你看着它,並檢查什麼是錯的 – SRMR

+1

https://gist.github.com/watert/13c38d269ea15aa8360f – StackUnderflow

回答

4

我想你忘了viewDidLoad()

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