TableView中的自定义单元格全为白色

时间:2018-05-13 19:40:34

标签: arrays swift tableview structure

我想改进视图控制器中的表格视图,使用自定义单元格。在我的单元格中,我想只显示一个带有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
            }
        }
    }

}

enter image description here

enter image description here

我不知道为什么我将这个表格视图变白,使任何图像变白。在我看到的另一种观点中,我写了相同的东西并且效果很好。 我希望有人可以帮助我。 感谢

1 个答案:

答案 0 :(得分:1)

GetMessage

viewDidLoad

还实施self.tableIntroduzioni.dataSource = self self.tableIntroduzioni.delegate = self

heightForRow