1.自己计算Cell的高度返回:

1>model中计算:

//
// InfoModel.h
// OCDemo
//
// Created by 思 彭 on 16/12/27.
// Copyright © 2016年 思 彭. All rights reserved.
// #import <Foundation/Foundation.h> @interface InfoModel : NSObject @property (nonatomic, copy) NSString *uid;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *desc;
@property (nonatomic, copy) NSString *headImage; @property (nonatomic, assign) CGFloat cellHeight; - (instancetype)initWithDictionary: (NSDictionary *)dic; @end
//
// InfoModel.m
// OCDemo
//
// Created by 思 彭 on 16/12/27.
// Copyright © 2016年 思 彭. All rights reserved.
// #import "InfoModel.h" @implementation InfoModel - (instancetype)initWithDictionary: (NSDictionary *)dic { if (self = [super init]) { self.title = dic[@"title"];
self.headImage = dic[@"img"];
self.desc = dic[@"desc"]; CGSize contentSize = [self.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - , ) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:]} context:nil].size;
self.cellHeight = contentSize.height + ;
}
return self;
} @end

2.自定义CellFrame类存储Cell高度:

//
// CellFrame.h
// OCDemo
//
// Created by 思 彭 on 16/12/28.
// Copyright © 2016年 思 彭. All rights reserved.
// #import <Foundation/Foundation.h>
#import "InfoModel.h" @interface CellFrame : NSObject @property (nonatomic, assign) CGRect headImgViewFrame;
@property (nonatomic, assign) CGRect titleLabelFrame;
@property (nonatomic, assign) CGRect contentlabelFrame;
@property (nonatomic, assign) CGFloat cellHeight; @property (nonatomic, strong) InfoModel *model; @end
//
// CellFrame.m
// OCDemo
//
// Created by 思 彭 on 16/12/28.
// Copyright © 2016年 思 彭. All rights reserved.
// #import "CellFrame.h" @implementation CellFrame - (void)setModel:(InfoModel *)model { _model = model;
_headImgViewFrame = CGRectMake(, , , );
CGSize contentSize = [model.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - , ) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:]} context:nil].size;
_titleLabelFrame = CGRectMake(CGRectGetMaxX(_headImgViewFrame) + , , K_SCREEN_WIDTH - - , );
_contentlabelFrame = CGRectMake(, CGRectGetMaxY(_headImgViewFrame) + , K_SCREEN_WIDTH - , contentSize.height);
_cellHeight = CGRectGetMaxY(_contentlabelFrame);
} @end

2.使用第三方Masonry自使用行高:

很方便,要求自己把约束要设置完全!!!

自适应UITableView的Cell高度问题的更多相关文章

  1. UITableView自动计算cell高度并缓存

    原文链接:http://www.jianshu.com/p/64f0e1557562 cell高度计算的历史 在iOS8之前,如果UITableViewCell的高度是动态的,如果想要显示正确的话,我 ...

  2. UITableView和UICollectionView的Cell高度的几种设置方式

    UITableViewCell 1.UITableView的Cell高度默认由rowHeight属性指定一个低优先级的隐式约束 2.XIB中可向UITableViewCell的contentView添 ...

  3. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

  4. iOS 开发中单元格cell高度自适应

    高度自适应分下面两种情况 1.用代码自定义的cell 用代码自定义的cell,cell高度自定义需要我们手动的去计算每个cell的字符串高度.然后返回对应的高度即可. 2.用XIB 或者 StoreB ...

  5. iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  6. 转:iOS开发之多种Cell高度自适应实现方案的UI流畅度分析

    本篇博客的主题是关于UI操作流畅度优化的一篇博客,我们以TableView中填充多个根据内容自适应高度的Cell来作为本篇博客的使用场景.当然Cell高度的自适应网上的解决方案是铺天盖地呢,今天我们的 ...

  7. UITableView自定义Cell中,纯代码编程动态获取高度

    在UITableView获取高度的代理方法中,经常需要根据实际的模型重新计算每个Cell的高度.直接的做法是在该代理方法中,直接根据模型来返回行高:另 [1]-(CGFloat)tableView:( ...

  8. 几种设置UITableView的cell动态高度的方法

    1.UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自 ...

  9. UITableView cell 半透明效果,改变cell高度时背景不闪的解决方法

    如果直接指定cell.backgroundColor = = [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 ...

随机推荐

  1. Oracle分区表!

    Oracle 数据库分区表的创建和操作 摘要:在大量业务数据处理的项目中,可以考虑使用分区表来提高应用系统的性能并方便数据管理,本文详细介绍了分区表的使用. 在大型的企业应用或企业级的数据库应用中,要 ...

  2. vs2012中添加lib,.h文件方法(原)

    项目.属性.C/C++.附加包含目录:填写附加头文件(*.h)所在目录 分号间隔多项项目.属性.链接器.附加库目录:填写附加依赖库(*.lib)所在目录 分号间隔多项项目.属性.链接器(点前面的+展开 ...

  3. ajax传递数组到后台

    //实体类 public class Person { private int ID{get;set;} private string Name{get;set;} private int Age{g ...

  4. js table的笔记,实现添加 td,实现搜索功能

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  5. border:none;与border:0;的区别

    border:none表示边框样式无,border:0表示边框宽度为0;当定义了border:none,即隐藏了边框的显示,实际就是边框宽度为0. 当定义边框时,必须定义边框的显示样式.因为边框默认样 ...

  6. x-ua-compatible的实践

    前提: 在ie8中测试 页面头部含有<!DOCTYPE html> 结果: <meta http-equiv="x-ua-compatible" content= ...

  7. 用systemd脚本自动启动node js程序

    vi /usr/lib/systemd/system/pano.service [Unit] Description=pano - main site of site_name.com Documen ...

  8. Sublime Text 3 使用

    Sublime Text3使用 下载安装 参考:http://www.downza.cn/soft/187996.html Sublime Text Build 3126 x64 Setup.exe下 ...

  9. 使用Birt开发报表

    间隔一段时间未使用Birt开发报表后,本文章记录Birt开发报表的常遇到的开发问题及解决措施,方便自己和园内其他朋友学习. 一.Birt连接数据库配置 1.连接DB2数据库: 1.1.birt的数据连 ...

  10. IP地址划分

    对于32位的IPV4地址来说,有5中IP地址类型 A类IP地址第一个字节是网络地址,后三个字节是主机地址,且最高位以0开头. 0000001  00000000   00000000 00000001 ...