簡體   English   中英

在UITableViewController子類中未調用tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath)

[英]tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) not getting called in UITableViewController subclass

UITableViewController numberOfSectionnumberOfRowsInSection被調用,但cellForRow沒有被調用。 可能是什么原因 ? 以下是tableViewController的代碼。

class GlobalSearchTableViewController: UITableViewController {

/// MARK: Properties

/// Delegate
weak var delegate: GlobalSearchTableViewControllerDelegate?

private var state = GlobalSearchTableState(searchResults: [])

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedSectionFooterHeight = 60
    tableView.sectionFooterHeight = UITableView.automaticDimension

    tableView.estimatedRowHeight = 60
    tableView.rowHeight = UITableView.automaticDimension
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
}

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

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

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    return UITableViewCell()
}

 extension GlobalSearchTableViewController: GlobalSearchTablePresenter {

func present(state: GlobalSearchTableState) {
      tableView.reloadData()

 }

嘗試返回細胞

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

 var cell : UITableViewCell!
        cell = tableView.dequeueReusableCell(withIdentifier: "cell")

        cell.textLabel?.text = dataArray[indexPath.row]

        return cell
}

嘗試添加tableView.delegate = selftableView.dataSource = self

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM