Пользовательская ячейка в TableView полностью белая - PullRequest
0 голосов
/ 13 мая 2018

Я хочу улучшить табличное представление в моем контроллере представления, используя пользовательскую ячейку.В моей ячейке я хочу отобразить только изображение с изображением.Это мой код:

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 голосов
/ 13 мая 2018

In viewDidLoad

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

также реализуют heightForRow

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