Swift 中的 TableView 问题(只有空行)

Problem with TableView in Swift (only empty Rows)

我的表格视图有问题。它是普通 ViewController.

中的表格视图

这是我的ViewController:

class ListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


var tableView:UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    tableView = UITableView(frame: view.bounds, style: .plain)
    tableView.delegate = self
    tableView.dataSource = self


    let cellNib = UINib(nibName: "PostTableViewCell", bundle: nil)
    tableView.register(cellNib, forCellReuseIdentifier: "postCell")

    view.addSubview(tableView)


    var layoutGuide:UILayoutGuide!
    layoutGuide = view.safeAreaLayoutGuide

    tableView.leadingAnchor.constraint(equalTo: layoutGuide.leadingAnchor).isActive = true
    tableView.topAnchor.constraint(equalTo: layoutGuide.topAnchor).isActive = true
    tableView.trailingAnchor.constraint(equalTo: layoutGuide.trailingAnchor).isActive = true
    tableView.bottomAnchor.constraint(equalTo: layoutGuide.bottomAnchor).isActive = true



    tableView.reloadData()


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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    12
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "postCell", for: indexPath) as! PostTableViewCell
    return cell
}

}

This is my PostTableViewCell.xib

我的 PostTableViewCell.swift 是空的。

这是我的结果: Iphone View

谢谢!

在两个函数中都指定了一个整数 return 而玩具只使用了一个数字

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

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 12 }

找到解决方案。刚刚添加了 rowHeight