[英]Unexpected Header View in UITableView's section using NSFetchedResultsController
It is easy to see, that the lightblue is a UITableViewHeaderFooterView
, and the white one is UITableViewCell
.很容易看出,浅蓝色是
UITableViewHeaderFooterView
,白色是UITableViewCell
。 I use NSFetchedResultsController
to load sections and groups from CoreData.我使用
NSFetchedResultsController
从CoreData负载部分和组。 Every blue header is a new section.每个蓝色标题都是一个新部分。
SOMETIMES (not always) there is a header view instead of a table view cell .有时(并非总是)有标题视图而不是表格视图单元格。 Why?
为什么?
In viewDidLoad
i register header View:在
viewDidLoad
我注册标题视图:
tableView.registerNib(UINib(nibName: "PBOUserWorkDayHeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: PBOUserWorkDayHeaderViewIdentifier)
What is more interesting, when I Debug View Hierarchy you can see, that there is my custom cell, just covered by header.更有趣的是,当我调试视图层次结构时,您可以看到,有我的自定义单元格,只是被标题覆盖。 Why?
为什么?
Is it iOS bug?是iOS错误吗? What do you think?
你怎么认为? Sth wrong with rendering or with my way of thinking?
渲染或我的思维方式有问题吗?
Since it is a problem with headers, I created a custom method to remove unnecessary headers every time when tableView
ask for `viewForHeaderInSection:.由于这是标题的问题,我创建了一个自定义方法,每次
tableView
请求`viewForHeaderInSection: 时删除不必要的标题。
Assuming that you know how to distinguish the headers from other views (in my case they have a custom class) and that you know that header views are direct subviews of tableView
you can remove them in following way:假设您知道如何区分标题与其他视图(在我的情况下,它们有一个自定义类)并且您知道标题视图是
tableView
直接子视图,您可以通过以下方式删除它们:
private func removeDoubledHeaders() {
let subviews = tableView.subviews.reverse()
var dates = [String]()
for view in subviews {
if let header = view as? PBOUserWorkDayHeaderView {
if let date = header.dateLabel.text {
if contains(dates, date) {
view.removeFromSuperview()
} else {
dates.append(date)
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.