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. [转]Linux软连接和硬链接

    1.Linux链接概念 Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接]硬连接指通过索引节 ...

  2. cocos2d触碰例子代码

    // // TestLayer.h // MiniTD // // Created by OnePiece on 12-7-30. // Copyright 2012年 __MyCompanyName ...

  3. Python-9 函数

    #1 内建函数 乘方:pow() >>> pow(2,3) 8 >>> 取绝对值:abs() >>> abs(-1) 1 >>> ...

  4. openwrt编译环境搭建

    1,首先安装ubuntu系统,这里安装的是虚拟机 2,安装openwrt编译所需环境  apt-get install build-essential libncures5-dev gawk libs ...

  5. git笔记 常规使用

    1. 创建分支    git checkout -b fetch_name 2. 添加快照进行登记 git add . 3.登记到仓库 git commit -m 'message' git comm ...

  6. 史上最强大的40多个纯CSS绘制的图形

    Square(正方形) #square { width: 100px; height: 100px; background: red; } Rectangle(矩形) #rectangle { wid ...

  7. Ninject之旅之二:开始使用Ninject(附程序下载)

    摘要 这篇文章介绍怎样将Ninject添加到实际的项目中,使用Ninject框架最基本的功能.首先用一个Hello World例子介绍怎么添加和使用Ninject.然后用一个更复杂的例子,介绍Ninj ...

  8. Java web--Filter过滤器分IP统计访问次数

    分IP统计访问次数即网站统计每个IP地址访问本网站的次数. 分析 因为一个网站可能有多个页面,无论哪个页面被访问,都要统计访问次数,所以使用过滤器最为方便. 因为需要分IP统计,所以可以在过滤器中创建 ...

  9. 9、SQL Server 操作数据

    插入数据 使用Insert Into 插入 if(exists(select * from sys.databases where name = 'webDB')) drop database web ...

  10. gb2312

    ---恢复内容开始--- 字符集 gb2312(字全)采用2两个字节(一个汉字) utf-8(只有汉字)采用3个字节(一个汉字) html就是负责描述页面的语义:css负责描述页面的样式:js负责描述 ...