【问题标题】:Custom cell is all white in TableView自定义单元格在 TableView 中是全白的
【发布时间】:2018-05-13 19:40:34
【问题描述】:

我想改进我的视图控制器中的表格视图,使用自定义单元格。在我的单元格中,我只想显示一个带有 imageView 的图像。 这是我的代码:

class ListaIntroduzioni: UIViewController, UITableViewDataSource, UITableViewDelegate {

    var listaIntroduzioni: [structIntroduzione] = []

    @IBOutlet weak var tableIntroduzioni: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        listaIntroduzioni = [
        structIntroduzione(titolo: "Premessa", nomeTesto: "premsessa", nomeImmagine: "001"),
        structIntroduzione(titolo: "Riguardo a Questa Raccolta", nomeTesto: "riguardo", nomeImmagine: "002"),
        structIntroduzione(titolo: "Introduzione", nomeTesto: "introduzione", nomeImmagine: "003"),
        structIntroduzione(titolo: "Ringraziamenti", nomeTesto: "ringraziamenti", nomeImmagine: "004"),
        structIntroduzione(titolo: "Commiato", nomeTesto: "commiato", nomeImmagine: "005"),
        structIntroduzione(titolo: "Dedica", nomeTesto: "dedica", nomeImmagine: "006")]

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableIntroduzioni.dequeueReusableCell(withIdentifier: "cellaIntroduzioni", for: indexPath) as! cellaListaIntroduzioni

        cell.imageView?.image = UIImage(named: listaIntroduzioni[indexPath.row].nomeImmagine)

        return cell
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        if segue.identifier == "SegueIntroduzione" {
            if let indexPath = tableIntroduzioni.indexPathForSelectedRow {
                let introduzione: structIntroduzione
                    introduzione = listaIntroduzioni[indexPath.row]
                let controller = (segue.destination as! UINavigationController).topViewController as! DettaglioIntroduzioni
                controller.dettaglioIntroduzione = introduzione
                controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
                controller.navigationItem.leftItemsSupplementBackButton = true
            }
        }
    }

}

我不知道为什么我要把这个表格视图变成白色,把任何图像都变白。在我的另一种观点中,我写了同样的东西并且效果很好。 我希望有人能帮助我。 谢谢

【问题讨论】:

    标签: arrays swift tableview structure


    【解决方案1】:

    viewDidLoad

    self.tableIntroduzioni.dataSource = self
    self.tableIntroduzioni.delegate = self
    

    同样实现heightForRow

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多