UITableView reloadSections/reloadData:标题视图变为空白

Dom*_*der 23 uitableview ios

我有一个带有一些部分的UITableView,每个部分都有自己的标题视图.当用户点击某个部分的标题视图时,该部分的所有行都将折叠.我做的是,我将该部分的行数设置为0,然后调用:

[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
Run Code Online (Sandbox Code Playgroud)

一切都按预期工作,除了一件事:该部分的标题视图变为白色空白.当我滚动表格时,标题再次变为正常.

所以我猜这张桌子的绘图有些问题.

一个有趣的事情是,如果我使用UITableViewRowAnimationFade代替,那么即使我滚动表格,标题仍然是白色空白.

当我只更新一个部分也没有问题 - 当我更新多个部分时,问题就出现了.

如果我使用

[self.tableView reloadData]
Run Code Online (Sandbox Code Playgroud)

相反,那么一切正常.

我使用的原因

[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
Run Code Online (Sandbox Code Playgroud)

是因为我想要动画.

使用beginUpdates/endupdates进行包装不起作用.

Dar*_*ren 44

我意识到这个问题提出的时间很长,但我认为下面给出的所有答案都是错误的.

我有同样的问题(与其他人的代码),当我意识到代码没有正确地重用表头时,这个帖子即将被愚弄.标题消失是因为代码只提供了UIView,而不是UITableViewHeaderFooterView,正确注册并设置为可重用.

看看这里的答案: 如何使用UITableViewHeaderFooterView?

当我设置一个可重复使用的标题时,我的空白标题消失了.


Dom*_*der 1

我找到了一个解决方法 - 不是很优雅,但它有效。我没有提供包含多个部分的 NSIndexSet,而是在 for 循环中调用 reloadSections,每次调用中仅包含一个部分。

好像:

    for (Element *eleSection in self.gruppenKoepfe) {
        if ( eleSection.type.integerValue == qmObjectTypeFormularSpalte || eleSection.type.integerValue == qmObjectTypeFormularZeile ) {
            [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:nCount] withRowAnimation:UITableViewRowAnimationFade];
        }
        nCount ++;
    }     
Run Code Online (Sandbox Code Playgroud)