https://lvwenhan.com/ios/449.html

#import "ViewController.h"
#import "MyTableViewCell.h"
static NSString *cellIdentifier = @"mycell"; @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) NSArray *listArr;
@property (strong, nonatomic) MyTableViewCell *cell;
@end @implementation ViewController
@synthesize listArr; - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.tableView registerNib:[UINib nibWithNibName:@"MyTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellIdentifier];
self.tableView.estimatedRowHeight = ;//很重要保障滑动流畅性
self.cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; self.listArr = @[@"Do any additional setup after loading the view, typically from a nib.",
@"test",
@"UITableViewCell 高度自适应一直是我们做动态Cell高度时遇到的最烦躁的问题,Cell动态高度计算可以去看看 sunny 的这篇文章介绍,今天主要和大家分享下我在使用 systemLayoutSizeFittingSize 系统自带方法计算高度的一些心得!"];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return listArr.count;
} - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableViewCell *cell = self.cell;
cell.myLabel.text = listArr[indexPath.row];
cell.contentView.translatesAutoresizingMaskIntoConstraints = NO;
CGFloat fittingHeight = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
return fittingHeight;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (self.cell == nil) {
UINib *nib = [UINib nibWithNibName:@"MyTableViewCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
self.cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
self.cell.myLabel.backgroundColor = [UIColor blueColor];
self.cell.myLabel.textColor = [UIColor whiteColor];
self.cell.myLabel.text = [listArr objectAtIndex:indexPath.row];
return self.cell;
} @end

最新文章

  1. PHP 面向对象
  2. 自定义 placeholder 文本颜色
  3. 《深入理解Spark:核心思想与源码分析》——SparkContext的初始化(叔篇)——TaskScheduler的启动
  4. IE6支持max-height及min-height解决方法
  5. abstract class和interface 知多少!!!
  6. Json常见问题
  7. 利用DataTable快速批量导数据
  8. Why Does Qt Use Moc for Signals and Slots(QT官方的解释:GUI可以是动态的)
  9. map map
  10. 用SWF来代替传统的帧动画
  11. 初识RabbitMQ系列之一:简单介绍
  12. 【转】十分有用的linux shell学习总结
  13. ●POJ 3608 Bridge Across Islands
  14. JS原生 未来元素监听写法
  15. input标签checkbox选中触发事件的方法
  16. Openstack-Ceilometer-Alarm运行机制
  17. springboot 简单使用 activemq 接收消息
  18. 《Inside C#》笔记(十三) 多线程 上
  19. jquery mouseover与mouseenter区别
  20. 【LongIntervalRetries】让我们来实现支付宝的异步回调方案

热门文章

  1. dwz Esc关闭dialog 窗口
  2. 使用jetty工具包处理url参数成map
  3. 如何在IntelliJ IDEA中使用Git .ignore插件忽略不必要提交的文件
  4. 一步一步开发sniffer(Winpcap+MFC)(五)莫道无人能识君,其实我懂你的心——解析数据包(转)
  5. chrome 浏览器的插件权限有多大?
  6. GitHub下载安装以及开源项目
  7. producter-consumer 他山之石
  8. 《Redis入门指南(第2版)》读后感
  9. Chrome F12 温故而知新 :因为重定向导致清空Network信息
  10. 第三部分:Android 应用程序接口指南---第四节:动画和图形---第一章 属性动画及动画与图形概述