UITableView reloadSections / reloadData:标题视图变为空白
我有一个UITableView与部分,每个都有自己的标题视图。 当用户点击某个部分的标题视图时,该部分的所有行都将折叠。 我所做的是将该部分的行数设置为0,然后调用:
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
一切都按预期工作,除了一件事情:该部分的标题视图变成白色的空白。 当我滚动表格,然后头再次变得正常。
所以我猜这个表的绘制有些问题。
一个有趣的事情是,如果我使用UITableViewRowAnimationFade而不是,那么即使当我滚动表,头还是白色的空白。
当我更新一个部分时,也没有问题 – 当我更新多个部分时,问题发生。
如果我使用
[self.tableView reloadData]
相反,那么一切正常。
我使用的原因
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationBottom];
是因为我想要animation。
用beginUpdates / endupdates包装不起作用。
我意识到自从提出这个问题以来,这是一个很长的时间,但我认为下面给出的所有答案都是不正确的。
我有同样的问题(与别人的代码),并被这个职位愚弄,当我意识到,代码是不是正在重复使用表头。 头文件消失是因为代码只是提供了一个UIView,而不是一个UITableViewHeaderFooterView,正确注册并设置重用。
看看这里的答案: 如何使用UITableViewHeaderFooterView?
当我设置一个可重用的标题时,空白标题消失了。
我find了一个解决方法 – 不是很优雅,但它的工作原理。 我没有提供多个节的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 ++; }
在Swift中:
您需要创build一个类为UITableViewHeaderFooterView
的子类并将其注册到表视图。 然后在viewForHeaderInSection
,你确实let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderView") as! YourHeaderView
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderView") as! YourHeaderView
,类似于你为UITableViewCells做的事情。 然后返回该header
。
欺骗性的东西是函数调用返回的UIView?
当它真的需要一个dequeuedReusableHeaderFooterView或者reloadData
会导致它消失
我有一个类似的问题,除了我试图删除/插入部分,我发现保留一个强大的属性指向整个标题视图(即不只是一个子视图)停止部分更新过程中消失。
例如属性和实例化
@property (nonatomic, strong) UIView *headerView;
-(UIView *)headerView { if ( !_headerView ) { _headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.bounds.size.width, 300)]; // add additional view setup, including subviews } return _headerView; }
并在tableView:(UITableView *)viewForHeaderInSection:(NSInteger)section
:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if ( section == theCorrectSection ) { return self.headerView; } return nil; }
我有同样的问题,并没有上述。 我的问题是,我正在隐藏的第一个标题,由于某种原因,超过10重新加载索引2的标题被设置为隐藏。 当我设置headerView.hidden = false它是好的。