简体   繁体   English

使用 NSFetchedResultsController 的 UITableView 部分中的意外标题视图

[英]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.

相关问题 具有NSFetchedResultsController的UITableView保留没有对象的节的标题 - UITableView with NSFetchedResultsController keep header for section without objects UITableView中带有NSFetchedResultsController的附加部分 - Additional section in UITableView with NSFetchedResultsController 使用NSFetchedResultsController的UITableView标头日期-Swift? - UITableView header dates using NSFetchedResultsController - Swift? 调整Xib的大小以用于UITableView的节标题视图 - Resizing xib to be used for UITableView's section header view 删除UITableView的部分后,标题视图的框架永远改变 - Frame of header view changed forever after deletion of UITableView's section 部分标题的UITableView自定义视图(内存泄漏)。 什么是使节的标题自定义视图正确的方法? - UITableView custom view for section header (memory leaks). What is correct method to make section's header custom view? 将NSFetchedResultsController与UITableView中的特定部分相关联 - Associate NSFetchedResultsController with specific section in UITableView UITableView重用节标题视图:使用UITableViewRowAnimationFade时标题视图消失 - UITableView reuse section header view: header view disappear when using UITableViewRowAnimationFade header 剖面图 UITableView 中的标签和按钮 - Lable and button in the header section view UITableView 剖面标题视图故障在普通的uitableview中 - Section header view glitch in plain uitableview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM