首页 > 解决方案 > 自定义单元格不出现在 tableView

问题描述

我的自定义单元格没有出现在我的表格视图中,我没有找到任何答案。

这是我的包含 TableView 的故事板: 故事板

这是我的 listController :

extension MatchListViewController: UITableViewDataSource {

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

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

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

        guard let cell = tableView.dequeueReusableCell(withIdentifier: "MatchCell", for: indexPath) as? MatchTableViewCell else {
            return UITableViewCell()
        }

        let match = matchArray[indexPath.row]

        cell.configure(nomDuMatch: match.matchName, scoreFinal: match.finalScore)

        return cell
    }
}

(我已经通过情节提要配置了 dataSourceDelegate)

customCell 标识符是正确的,我真的不明白为什么启动时什么都没有出现。

随时问我更多图片/信息!

编辑 :

这是结果: 结果

标签: iosswifttableview

解决方案


你需要实施

func tableView(_ tableView: UITableView, 
     heightForRowAt indexPath: IndexPath) -> CGFloat {

  return 100 // or any value 
}

或使用自动单元格并在 IB 中正确设置约束,因为您似乎有约束问题并将其设置为viewDidLoad

tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableViewAutomaticDimension

推荐阅读