我有一些静态单元格,这不想通过标签中的超重内容来更改其大小。每个单元格中都有所有约束(top
,bottom
,leading
,tralling
),我也有以下代码:
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
}
}
}
}
numberOfLines也为0。
当我看到此视图时,它不起作用,但是如果我向下滑动,它看起来像这样:
请,有解决这个问题的主意吗? :(
答案 0 :(得分:1)
您需要更新代码,原因不清楚发生了什么。
无论如何,您都应使用或:
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
}
不是两者