我想在代码中用示例数据填充基本tableview。这里是我的ViewController:为什么我的tableView没有被填充?
import UIKit
class TableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var postTableView: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "postcell", for: indexPath)
cell.textLabel?.text = "title"
cell.detailTextLabel?.text = "detail"
return cell
}
}
我敢肯定,这个名字"postcell"
是正确的,我已经迷上了的tableView到ViewController作为数据源和委托。
当我在iOS模拟器中运行代码时,没有显示出单元格。这是我所看到的:
堆叠视图属性
我不希望使用UITableViewController
如何获取表格单元格?
在你的故事板中,你有没有确保视图控制器的类是'TableViewController'? – TylerTheCompiler
@MrSaturn是的,它是TableViewController –
@MrSaturn我已经添加了我的故事板,这有帮助吗? –