UITableView reloadSections / reloadData:标题视图变为空白 [英] UITableView reloadSections/reloadData: header view becomes blank
问题描述
我有一个带有一些部分的UITableView,每个部分都有自己的标题视图。
当用户点击某个部分的标题视图时,该部分的所有行都将崩溃。我做的是,我将该部分的行数设置为0,然后调用:
I have a UITableView with some sections, each has its own header view. When user taps on the header view of a section, all rows of that section will collapse. What i do is, I set the number of row of that section to 0, and then call :
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
一切都按预期工作,除了一件事:该部分的标题视图变为白色空白。当我滚动表格时,标题再次变为正常。
Everything works as expected, except one thing : the header view of the section becomes white blank. When i scroll the table, then the header becomes normal again.
所以我猜这个表的绘制存在一些问题。
So i guess there's some problem with the drawing of the table.
有趣的是,如果我使用UITableViewRowAnimationFade,那么即使我滚动表格,标题仍然是白色空白。
One funny thing is, if i use UITableViewRowAnimationFade instead, then even when i scroll the table, the header is still white blank.
当我只更新一个部分时也没有问题 - 当我更新多个部分时会出现问题。
When I update just ONE section there is also no problem - when I update more than one section the problem occurs.
如果我使用
[self.tableView reloadData]
相反,一切正常。
我使用的原因
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
是因为我想要动画。
使用beginUpdates / endupdates进行包装不起作用。
Wrapping with beginUpdates / endupdates does not work.
推荐答案
我找到了解决办法 - 不是很优雅,但它有效。
我没有提供带有多个部分的NSIndexSet,而是在for循环中调用reloadSections,每次调用只有一个部分。
I found a work-around - not very elegant, but it works. Instead of providing a NSIndexSet with more than one section, I call the reloadSections within a for-loop with only one section in each call.
如下所示:
for (Element *eleSection in self.gruppenKoepfe) {
if ( eleSection.type.integerValue == qmObjectTypeFormularSpalte || eleSection.type.integerValue == qmObjectTypeFormularZeile ) {
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:nCount] withRowAnimation:UITableViewRowAnimationFade];
}
nCount ++;
}
这篇关于UITableView reloadSections / reloadData:标题视图变为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!