UITableView自动行高(基于内容)-仍然是相同的错误
我希望tableview中的行根据内容2标签(总共3行文本)进行动态缩放。我不断收到此错误,我的单元格设置为标准大小:UITableView自动行高(基于内容)-仍然是相同的错误,uitableview,dynamic,row,height,swift5,Uitableview,Dynamic,Row,Height,Swift5,我希望tableview中的行根据内容2标签(总共3行文本)进行动态缩放。我不断收到此错误,我的单元格设置为标准大小: [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and usi
[Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. We're considering the collapse unintentional and using standard height instead. Cell: <ProjectSammy.AnnotationCell: 0x106061d80; baseClass = UITableViewCell; frame = (0 647.5; 414 70); autoresize = W; layer = <CALayer: 0x282d09ee0>>
我将TableView上的行设置为automic维度:
private func configureTableView() {
tableView = UITableView(frame: view.bounds, style: .grouped)
view.addSubview(tableView)
tableView.delegate = self
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
tableView.backgroundColor = .clear
tableView.register(AnnotationCell.self, forCellReuseIdentifier: AnnotationCell.reuseIdentifier)
tableView.register(AnnotationHeaderCell.self, forHeaderFooterViewReuseIdentifier: AnnotationHeaderCell.reuseIdentifier)
tableView.sectionHeaderHeight = 40
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 70
}
我甚至在委托方法中提供了估计的行高:-不需要1-可以直接在tableview上完成
哪里出错?估计的行高无法设置为自动标注。您必须将其设置为特定的数字,尝试将其设置为44,这是默认的行高。谢谢!这是解决方案的一部分,我还将标签直接添加到单元格,而不是contentView。也改变了,一切都好!
private func configureTableView() {
tableView = UITableView(frame: view.bounds, style: .grouped)
view.addSubview(tableView)
tableView.delegate = self
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
tableView.backgroundColor = .clear
tableView.register(AnnotationCell.self, forCellReuseIdentifier: AnnotationCell.reuseIdentifier)
tableView.register(AnnotationHeaderCell.self, forHeaderFooterViewReuseIdentifier: AnnotationHeaderCell.reuseIdentifier)
tableView.sectionHeaderHeight = 40
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 70
}