解决:
1.初始化一个可变字典
2.在willDisplayHeaderView存储高度
3.在estimatedHeightForHeaderInSection判断是否已有高度
4.heightForHeaderInSection判断是否存储
//头部高度存储
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
// NSLog(@"HeaderView%f",view.size.height);
DynamicListItem * item = self.dynamicArr[section];
CGFloat height = [[self.headerHeightDic objectForKey:item.dynamicId] doubleValue];
if (height <= 0) {
[self.headerHeightDic setObject:@(view.size.height) forKey:item.dynamicId];
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
DynamicListItem * item = self.dynamicArr[section];
CGFloat height = [[self.headerHeightDic objectForKey:item.dynamicId] doubleValue];
if (height > 0) {
return height;
}
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section{
DynamicListItem * item = self.dynamicArr[section];
CGFloat height = [[self.headerHeightDic objectForKey:item.dynamicId] doubleValue];
if (height > 0) {
return height;
}
return 360;
}