Регистрация ячеек таблицы обнаружила ноль при распаковке - PullRequest
0 голосов
/ 07 января 2019

Я пытаюсь создать табличное представление в представлении контейнера, чтобы я мог анимировать его, в отличие от обычного UITableViewController.

В раскадровке создан UIViewController с UIView в качестве «контейнера вида». Внутри containerView находится tableView. ИДК, почему он продолжает давать мне ноль.

class SearchViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.dataSource = self
        tableView.delegate = self

        tableView.register(SearchViewCell.self, forCellReuseIdentifier: "SearchResult")
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "SearchResult", for: indexPath) as! SearchViewCell
        cell.addressLabel.text = "Hello"
        cell.subtitleLabel.text = "There"
        return cell
    }   
}

SearchViewCell

class SearchViewCell: UITableViewCell {
    @IBOutlet weak var addressLabel: UILabel!
    @IBOutlet weak var subtitleLabel: UILabel!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }
}

1 Ответ

0 голосов
/ 07 января 2019

1- Этот регистр

tableView.register(SearchViewCell.self, forCellReuseIdentifier: "SearchResult")

действительно только для программно созданных пользовательских ячеек (явно без розеток)

2- Для ячеек-прототипов (когда вы создаете ячейку внутри таблицы в макете), вам не нужен регистр

3- Если вы создали макет ячейки в xib, то есть другой способ регистрации

 tableView.register(UINib(nibName: "SearchViewCell", bundle: nil), forCellReuseIdentifier: "cellID")
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...