首页 > 解决方案 > viewForHeaderInSection 没有在 reloadData 上被调用

问题描述

viewForHeaderInSection 没有在 reloadData 上被调用。加载视图时如何第一次调用它。很奇怪。有什么帮助吗?我已经实现了以下委托方法。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 1500.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return  UITableViewAutomaticDimension;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {}

标签: iosobjective-cuitableviewuitableviewsectionheader

解决方案


heightForHeaderInSection可能会0因为UITableViewAutomaticDimension不起作用而返回。为了UITableViewAutomaticDimension工作,您必须设置所有相对于单元格容器视图的左侧、右侧、底部和顶部约束。


推荐阅读