估计行高怪异的HeightForHeaderInSection [英] estimatedHeightForHeaderInSection acting weird
问题描述
我已经在表格视图中添加了一个自定义标头,它使用动态类型,并且希望它具有自定义大小.
I've added a custom header to my table view and it uses dynamic type and I want it to be self sizing.
所以我将此添加到了viewDidLoad
:
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension
这是我其余的表格视图方法:
And this to the rest of my table view methods:
override func tableView(tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
return 22
}
然后我的标头单元太大,无法自动调整大小,我收到此错误消息:
Then my header cells were way too large and not self sizing and I got this error message:
Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.
所以我开始玩耍,删除了estimatedHeightForHeaderInSection
方法并改为实现了estimatedHeightForFooter
.然后我的标题看起来很完美!但是页脚也开始显示,这是我不想要的.因此,我添加了heightForFooter
方法并将其设置为0,现在,所有这些方法都像我想的那样工作了.
So I started playing around and I removed the estimatedHeightForHeaderInSection
method and implemented estimatedHeightForFooter
instead. And then my header looked perfect! But a footer started showing too, which I didn't want. So I added the heightForFooter
method and set it to 0, and now it all works like I wanted in the first place.
不过,我发现这很奇怪.我是新手,但我希望estimatedHeightForHeader
用于页眉,而estimatedHeightForFooter
用于页脚.这是一个错误吗?难道我做错了什么?有没有更好的方法可以完成我想做的事情?
I'm finding this very weird, though. I'm new at all this, but I expected estimatedHeightForHeader
to work for the header and estimatedHeightForFooter
to work for the footer. Is this a bug? Am I doing something wrong? Is there a better way to accomplish what I'm trying to do?
谢谢.
丹尼尔
我接受了Omkar的回答,因为当时它对我有用,但是我仍然不明白为什么我不应该同时使用这两种方法.不过,我在标题中使用的是常规单元格,现在我发现这样做会导致各种奇怪的事情发生.因此,我只是以编程方式更改了UITableViewHeaderFooterView,现在一切正常,但是我确实必须实现这两种方法,就像我首先想到的那样,否则标题将无法正确调整大小.
I accepted Omkar's answer because it worked for me at the time, but I still didn't understand why I shouldn't use both methods. I was using a regular cell for my header, though, and now I found out that doing that causes all sorts of weird things to happen. So I just programmatically changed the UITableViewHeaderFooterView instead, and now it all works out, but I do have to implement both methods, like I first thought, otherwise the header doesn't resize properly.
推荐答案
不要同时使用这两者从您的代码中将其删除
Don't use both remove this from your code
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension
这篇关于估计行高怪异的HeightForHeaderInSection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!