利用iOS8新特性计算cell的实际高度
在计算cell的实际高度是 我们一般是通过计算frame 拿到最底部一个控件的最大Y值从而的到cell 的高度 算来算去 比较麻烦
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类型:

利用iOS8新特性计算cell的实际高度的更多相关文章
- iOS:通过Self-Sizing Cells新特性自动计算cell的高度
iOS8 新特性Self-Sizing Cells,自动计算cell的高度 一.简单介绍 UITableView是iOS开发最常用的一个控件,通过代理和数据源方法,几乎能实现各种各样的列表功能.在这里 ...
- Microsoft Tech Summit 2018 课程简述:利用 Windows 新特性开发出更好的手绘视频应用
概述 Microsoft Tech Summit 2018 微软技术暨生态大会将于10月24日至27日在上海世博中心举行,这也会是国内举办的最后一届 Tech Summit,2019 年开始会以 Mi ...
- iOS8新特性(1)——UIAlertController
一.iOS8介绍 iOS8 新特性,主要是UI上进行了统一 1.UIAlertController 2.UIPresentaionController:管理所有通过modal出来的控制器(看笔记) 3 ...
- iOS8 新特性
iOS8新特性主要体现在4方面 1.UIAlertController 对alert&actionSheet的封装 UIAlertController.h 提示框按钮的选择 typedef N ...
- ios8新特性widget开发-b
os8发布已经有一段时间了,伴随着ios8同时也出现了许多新的特性,ios系统将会越来越开放,这是好事.其中一个新特性就是在下拉通知栏里加入了个性的widget,开发者可以自己定义widget的样式内 ...
- 利用HTML5新特性改变浏览器地址后不刷新页面
原文:http://www.cnblogs.com/xuchengzone/archive/2013/04/18/html5-history-pushstate.html 作为一个程序员,上Git ...
- Exadata 18.1新特性--计算节点升级增强
新的计算节点升级增强能大幅缩短升级花费的时间,最快能减少40%的时间,具体的增强主要体现在以下方面: 1.计算节点操作系统的备份工作. 以前计算节点操作系统的备份工作是在正式升级之前执行,在滚动升级过 ...
- iOS8新特性
1. App Extension Programming Guide 2.LocalAuthentication.framework - Touch ID Authentication 3.Local ...
- 利用H5新特性判断文件大小
HTML代码部分: 思路:下面代码中我利用css的z-index属性将input="file”标签隐藏在了id=btnSelect元素下面,通过触发a标签的点击后,弹出文件选择框.下面的ma ...
随机推荐
- POJ 1655-Balancing Act(树形dp)
题意: 求n个节点的树中哪个节点删除以后得到的最大连通分量最小. 分析:同上题 #include <map> #include <set> #include <list& ...
- sublime Text2.0.2注册码
----- BEGIN LICENSE ----- Andrew Weber Single User License EA7E-855605 813A03DD 5E4AD9E6 6C0EEB94 BC ...
- java@ 利用ArrayList实现dijkstra算法以及topological 排序算法(java.util.ArrayList)
package dataStructure; import java.util.ArrayList; import java.util.LinkedList; import java.util.Que ...
- EM算法原理简析——图解
一. 扯淡 转眼间毕业快一年了,这期间混了两份工作,从游戏开发到算法.感觉自己还是喜欢算法,可能是大学混了几年算法吧!所以不想浪费基础... 我是个懒得写博客的人,混了几年coding,写的博客不超过 ...
- Java持久化存储对象Properties的方法list、store、load
package FileDemo; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStrea ...
- 转载 DevOps的基本原则与介绍
转载原地址: http://www.cnblogs.com/wintersun/p/3339047.html DevOps的基本原则与介绍 DevOps这个术语是developer与operatio ...
- Linux就是这个范儿之第一次亲密接触(3)
原创作品,允许转载,转载时请务必以超链接形式标明文章原始出处 .作者信息和本声明.否则将追究法律责 1.4 返璞归真的命令行 有一种说法,现代计算机不是靠电力驱动,而是靠“鼠标”.多少应用程序的界面需 ...
- PowerDesigner 物理数据模型(PDM)
PowerDesigner 物理数据模型(PDM) 说明 数据库脚本sqldatabasegeneration存储 目录(?)[+] 一. PDM 介绍 物理数据模型(Physical ...
- iOS UICollectionView基础
转载自:http://www.cnblogs.com/wayne23/p/4013522.html 初始化部分: UICollectionViewFlowLayout *flowLayout= [[ ...
- sgu 101 无向图有双重边的欧拉路径
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> ...