在计算cell的实际高度是 我们一般是通过计算frame  拿到最底部一个控件的最大Y值从而的到cell 的高度  算来算去  比较麻烦

其实,iOS8已经提供了直接通过Cell高度自适应的方法了,根本不用计算Cell高度,就可以搞定不等高Cell  这个方法即对系统cell有效 也对通多xib创建的cell有效:
 
方法:设置tableView的估算Cell高度&rowHeight值为自动计算模式
    self.tableView.estimatedRowHeight = ;  //  随便设个不那么离谱的值
self.tableView.rowHeight = UITableViewAutomaticDimension;

注意:::不能实现heightForRow代理方法!

代码:

#import "TESTTableViewController.h"
#import "TESTTableViewCell.h"
@interface TESTTableViewController ()
@property (nonatomic,strong) NSArray *contentAry;
@end @implementation TESTTableViewController - (void)viewDidLoad {
[super viewDidLoad]; self.tableView.estimatedRowHeight = ; // 随便设个不那么离谱的值
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.contentAry = @[@"哈哈哈",@"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈",@"啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈",@"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈"];
}
#pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID = @"cell"; //利用系统自带cell类型
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// if (cell == nil) {
// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
//
// }
// cell.textLabel.numberOfLines = 0;
// cell.textLabel.text = self.contentAry[indexPath.row];
// return cell; //通过xib构建cell
TESTTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
NSArray *nibs = [[NSBundle mainBundle]loadNibNamed:@"TESTTableViewCell" owner:nil options:nil];
cell = [nibs firstObject];
}
cell.contentText.numberOfLines = ;
cell.contentText.text = self.contentAry[indexPath.row];
return cell;
}
@end

效果图:

通过xib创建的cell:

系统自带cell类型:

参考资料:简书  demo(提取码:a75d)

利用iOS8新特性计算cell的实际高度的更多相关文章

  1. iOS:通过Self-Sizing Cells新特性自动计算cell的高度

    iOS8 新特性Self-Sizing Cells,自动计算cell的高度 一.简单介绍 UITableView是iOS开发最常用的一个控件,通过代理和数据源方法,几乎能实现各种各样的列表功能.在这里 ...

  2. Microsoft Tech Summit 2018 课程简述:利用 Windows 新特性开发出更好的手绘视频应用

    概述 Microsoft Tech Summit 2018 微软技术暨生态大会将于10月24日至27日在上海世博中心举行,这也会是国内举办的最后一届 Tech Summit,2019 年开始会以 Mi ...

  3. iOS8新特性(1)——UIAlertController

    一.iOS8介绍 iOS8 新特性,主要是UI上进行了统一 1.UIAlertController 2.UIPresentaionController:管理所有通过modal出来的控制器(看笔记) 3 ...

  4. iOS8 新特性

    iOS8新特性主要体现在4方面 1.UIAlertController 对alert&actionSheet的封装 UIAlertController.h 提示框按钮的选择 typedef N ...

  5. ios8新特性widget开发-b

    os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...

  6. 利用HTML5新特性改变浏览器地址后不刷新页面

    原文:http://www.cnblogs.com/xuchengzone/archive/2013/04/18/html5-history-pushstate.html   作为一个程序员,上Git ...

  7. Exadata 18.1新特性--计算节点升级增强

    新的计算节点升级增强能大幅缩短升级花费的时间,最快能减少40%的时间,具体的增强主要体现在以下方面: 1.计算节点操作系统的备份工作. 以前计算节点操作系统的备份工作是在正式升级之前执行,在滚动升级过 ...

  8. iOS8新特性

    1. App Extension Programming Guide 2.LocalAuthentication.framework - Touch ID Authentication 3.Local ...

  9. 利用H5新特性判断文件大小

    HTML代码部分: 思路:下面代码中我利用css的z-index属性将input="file”标签隐藏在了id=btnSelect元素下面,通过触发a标签的点击后,弹出文件选择框.下面的ma ...

随机推荐

  1. 发送一个简单的HTTP GET请求并且取回响应。

    string uri="http//www.baidu.com"; WebClient wc = new WebClient(); Console.WriteLine(" ...

  2. 关于Excel中的需求或者是用例导入到QC中遇到的问题

    Excel 中导入用例到QC时,会提示如图所示的错误信息:   解决方案: 我的电脑-->属性->高级-->性能设置-->添加QC程序 

  3. Android UI -- 的基础知识。

    在介绍基础知识之前先明确几个基本的概念 View 视图是所有可视组件的基类,所有的UI控件包括布局类都是从View派生出来的. ViewGroup ViewGroup是View的扩展,可以放置多个Vi ...

  4. CSS换行:word-wrap、word-break和text-wrap区别

    一.word-wrap:允许对长的不可分割的单词进行分割并换行到下一行.(中英文处理效果一样) word-wrap有两个取值: 1.word-wrap: normal:只在允许的断字点换行(浏览器保持 ...

  5. CUDA学习资料分享(随时更新)

    1.Programming_Massively_Parallel_Processors.pdf 2.CUDA_C_Programming_Guide.pdf 3.CUDA范例精解通用GPU编程.pdf ...

  6. DOS命令关闭进程

    1.开始-运行,输入cmd后回车; 2.在DOS提示符下,先用命令 tasklist 回车来获取进程的 PID(例如获取了Explorer.EXE进程的PID为1988); 3.然后再输入命令:tas ...

  7. C#中的强类型说明

    转载原地址: http://www.cnblogs.com/JeffreyZhao/archive/2009/02/27/mvc-use-strong-type-everywhere.html 我们继 ...

  8. ubuntu 忘记用户名及密码解决办法

    1.重启系统 2.长按Shift键,直到出现菜单.选择recovery mode,即恢复模式 3.选择root  4.# 后面敲入 cat /etc/shadow 查看用户名 5.# passwd & ...

  9. fastjson把对象转化成json避免$ref

    转自http://blog.csdn.net/wxwzy738/article/details/30244993 DisableCircularReferenceDetect来禁止循环引用检测: JS ...

  10. webService 接口调用配置

    1.配置XML文件,如果新建一个XML文件需要在applicationContext.xm里面配置一下 <import resource="cxf-client.xml" / ...