Twing90
Twing90

Reputation: 417

Custom cell is all white in TableView

I want to improve a table view in my view controller, whit a custom cell. In my cell I want to display only an image, with an imageView. This Is my code:

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

I don't know why I'm getting this table view white, whiteout any images. In the other view that I have I wrote the same things and it works good. I hope that somebody can help me. thanks

Upvotes: 0

Views: 25

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100533

In viewDidLoad

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

also implement heightForRow

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

Upvotes: 1

Related Questions