Проблема с TableView в Swift (только пустые строки) - PullRequest
0 голосов
/ 10 апреля 2020

У меня проблема с моим столом. Это просмотр таблицы в обычном 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
}

}

Это мой PostTableViewCell. xib

Мой PostTableViewCell. swift пуст.

Это мой результат: Iphone Просмотр

Спасибо!

Ответы [ 2 ]

0 голосов
/ 10 апреля 2020

Найдите решение. Просто добавил строку Высота

0 голосов
/ 10 апреля 2020

В обеих функциях спектры возвращают int, а игрушка использует только число

fun c numberOfSections (в tableView: UITableView) -> Int {return 1}

fun c tableView (_ tableView: UITableView, раздел numberOfRowsInSection: Int) -> Int {return 12}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...