为什么 - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section 没有被调用?

5
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    [view vChangeBackgroundToCyan];
}

之后

[self.delegateForTableController.tvDelegated insertSections:[NSIndexSet indexSetWithIndex:ip.section] withRowAnimation:UITableViewRowAnimationRight];

那么如何调用它们呢?


你是否遵循了UITableView的代理协议? - user2071152
那个代理看起来不错..你能给我们展示一下tableView:viewForSection:方法吗? - Daij-Djan
2个回答

8

tableView:viewForHeaderInSection:返回的类必须是UITableViewHeaderFooterView的子类,才能调用tableView:willDisplayHeaderView:forSection:方法。

如果返回的视图是其他类型,则tableView:willDisplayHeaderView:forSection:方法将不会被调用。


1
据我所知,只有在使用自定义视图– tableView:viewForHeaderInSection:时,才会调用- tableView:willDisplayHeaderView:forSection:方法。
同时,希望您的委托引用不是nil

2
从iOS9开始,即使没有实现tableView:viewForHeaderInSection:,也会调用tableView:willDisplayHeaderView:forSection: - Laevand

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接