我現在有,設置了自定義數據源在其init函數一個UITableViewController:的UITableViewController與自定義數據源沒有顯示細胞
class BookmarkTableViewController: UITableViewController {
var date: Date
// MARK: - Init
init(date: Date, fetchAtLoad: Bool) {
self.date = date
super.init(style: .plain)
self.tableView.dataSource = BookmarkDataSource(date: date)
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
// ...
}
自定義數據源如下:
class BookmarkDataSource: NSObject {
let date: Date
init(date: Date) {
self.date = date
super.init()
}
}
// MARK: - UITableViewDataSource
extension BookmarkDataSource: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = "Test content"
return cell
}
}
但是,當我在模擬器上或設備上運行時,表格視圖中什麼也沒有顯示。有誰知道我錯過了什麼?
注:我使用的Xcode 8.0 Beta版和雨燕3.
是的!就是這個。謝謝! – Aliou
我弄糟了dataSource變量的創建,但你明白了! – bradkratky