美文网首页
iOS tableview使用masonry与 UITable

iOS tableview使用masonry与 UITable

作者: 橙_知足常乐 | 来源:发表于2021-12-16 19:02 被阅读0次

解决:
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;
}

相关文章

网友评论

      本文标题:iOS tableview使用masonry与 UITable

      本文链接:https://www.haomeiwen.com/subject/taivfrtx.html