如何制作动态Uitableview页眉高度
我不明白为什么我不能根据文本量来调整我的节标题高度 我在这方面找到的大多数信息提供了如何根据文本量调整单元格行高度的以下步骤:如何制作动态Uitableview页眉高度,uitableview,swift3,uitableviewsectionheader,Uitableview,Swift3,Uitableviewsectionheader,我不明白为什么我不能根据文本量来调整我的节标题高度 我在这方面找到的大多数信息提供了如何根据文本量调整单元格行高度的以下步骤: 将标签添加到情节提要中的tableView单元格,并将自动约束设置为标签 在属性检查器中将行数设置为0 将以下代码添加到ViewDidLoad中的swift文件: tableView.estimatedRowHeight = 50.0 tableView.rowHeight = UITableViewAutomaticDimension 当我创建具有动态高度的单元格
tableView.estimatedRowHeight = 50.0
tableView.rowHeight = UITableViewAutomaticDimension
tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
tableView.estimatedSectionHeaderHeight = 50.0;
但这不起作用。我知道指定行高的代码将抵消自动布局约束,因此我认为我的一些代码可能存在问题,这些代码使节在点击时展开/折叠,并且它有一个图像(一个箭头,根据节是展开还是折叠指向上/下)。这就是我认为可能导致问题的原因:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
//recast your view as a UITableViewHeaderFooterView
let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
header.contentView.backgroundColor = UIColor.colorWithHexString(hexStr: "#4f9c25")
header.textLabel?.textColor = UIColor.white
if let viewWithTag = self.view.viewWithTag(kHeaderSectionTag + section) {
viewWithTag.removeFromSuperview()
}
let borderTop = UIView(frame: CGRect(x:0, y:0, width: tableView.bounds.size.width, height: 1.0))
borderTop.backgroundColor = UIColor.self.init(red: 5/255, green: 16/255, blue: 28/255, alpha: 1.0)
header.addSubview(borderTop)
let headerFrame = self.view.frame.size
let theImageView = UIImageView(frame: CGRect(x: headerFrame.width - 32, y: 13, width: 18, height: 18));
theImageView.image = UIImage(named: "Chevron-Dn-Wht")
theImageView.tag = kHeaderSectionTag + section
header.addSubview(theImageView)
// make headers touchable
header.tag = section
let headerTapGesture = UITapGestureRecognizer()
headerTapGesture.addTarget(self, action: #selector(WeedsControlledVC.sectionHeaderWasTouched(_:)))
header.addGestureRecognizer(headerTapGesture)
}
如果这不是问题所在,我也在下面的线程中尝试了这些建议,但我也无法让它们发挥作用
知道我做错了什么吗