我有一些静态的细胞,这不想改变他们的大小超重的内容标签。我在每个单元格中都有所有约束(topbottomleadingtralling),还有以下代码:

import UIKit

class FilmTableViewController: UITableViewController {

    @IBOutlet weak var posterView: UIImageView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var yearLabel: UILabel!
    @IBOutlet weak var directorLabel: UILabel!
    @IBOutlet weak var actorsLabel: UILabel!
    @IBOutlet weak var countryLabel: UILabel!
    @IBOutlet weak var plotLabel: UILabel!
    @IBOutlet weak var RatingLabel: UILabel!

    private let networkingService = NetworkingService()
    var filmImbdbID = ""

    override func viewDidLoad() {
        super.viewDidLoad()
        loadFilm(filmImbdbID)


    }

    override func viewDidAppear(_ animated: Bool) {
        tableView.rowHeight = UITableView.automaticDimension
        tableView.estimatedRowHeight = 80
    }

    private func loadFilm(_ film: String) {

        networkingService.fetchFilmRecording(matching: film) { [weak self] response in

            guard let `self` = self else {
                return
            }

            self.directorLabel.text = response.recordings?.director
            self.titleLabel.text = response.recordings?.title
            self.yearLabel.text = response.recordings?.year
            self.actorsLabel.text = response.recordings?.actors
            self.countryLabel.text = response.recordings?.country
            self.plotLabel.text = response.recordings?.plot
            self.RatingLabel.text = response.recordings?.rating

            if let imageUrl = URL(string: response.recordings!.poster) {
                guard let data = try? Data(contentsOf: imageUrl) else { return }
                let image = UIImage(data: data)
                self.posterView.image = image
            }
        }
    }
}

行数也是0。
当我看到这个视图时,它不起作用,但是如果我向下滑动它看起来像这样:
拜托,想办法修一下吗?:(

最佳答案

你需要更新你的代码,因为不清楚发生了什么。
无论如何,您应该使用或:

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 80

或委托方法
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableView.automaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableView.automaticDimension
}

不是两者都有

10-04 21:33