iOS tableview使用masonry与 UITableViewAutomaticDimension自适应高度弹跳问题

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容