第一 CPU考虑方向

1. 对象创建;

1.1 TableView初始化

#pragma 懒加载
- (UITableView *)tableView{if (!_tableView) {_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - self.cycleScrollView2.frame.size.height)];_tableView.delegate = self;_tableView.dataSource = self;[self.view addSubview:_tableView];}return _tableView;
}

1.2 复用cell

从 iOS 6 以后,我们在 UITableView 和 UICollectionView 中可以复用 Cell以及各个 Section 的 Header 和 Footer。

确保TableviewCell/Header/Footer使用了复用机制, 而不是每一次都创建;

@interface HomeVC ()<UITableViewDataSource, UITableViewDelegate>@property (nonatomic, strong) UITableView *tableView;@endstatic NSString *cellId = @"Cell";@implementation HomeVC- (void)viewDidLoad {[super viewDidLoad];self.myTableView.delegate = self;self.myTableView.dataSource = self;
//第一种注册cell<nib文件类HomeTableViewCell>[self.tableView registerNib:[UINib nibWithNibName:@"HomeTableViewCell" bundle:nil] forCellReuseIdentifier:cellId];//第二种注册Cell<纯手工打造的HomeVC>
// [self.tableView registerClass:[HomeVC class]forCellReuseIdentifier:cellId];}#pragma 代理- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{//获取重用池中的cellHomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];//如果没有取到,就初始化if (!cell) {cell = [[HomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];}cell.cellNameLab.text = @"Name";return cell;
}
1.2.1 以下为重用相关API
// 复用 Cell:
- [UITableView dequeueReusableCellWithIdentifier:];
- [UITableView registerNib:forCellReuseIdentifier:];
- [UITableView registerClass:forCellReuseIdentifier:];
- [UITableView dequeueReusableCellWithIdentifier:forIndexPath:];
// 复用 Section 的 Header/Footer:
- [UITableView registerNib:forHeaderFooterViewReuseIdentifier:];
- [UITableView registerClass:forHeaderFooterViewReuseIdentifier:];
- [UITableView dequeueReusableHeaderFooterViewWithIdentifier:];

2. TabelView 代理

2.1 避免快速滑动情况下开过多线程。

cell中的图片开线程异步加载SDWebImage(异步操作)。但是线程开过多了会造成资源浪费,内存开销过大。图片过多时可以不要一滚动就走cellForRow方法,可以在scrollview的代理方法中做限制,当滚动开始减速的时候才加载显示在当前屏幕上的cell(通过tableview的dragging和declearating两个状态也能判断)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];//如果没有取到,就初始化if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];}cell.textLabel.text = @"Name";BOOL canLoad = !self.tableView.dragging && !_tableView.decelerating;if  (canLoad) {//开始loaddata,异步加载图片NSLog(@"开始加载图片");}return cell;
}// 滚动停止时,触发该函数
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {//刷新tableview// [self.tableView reloadData];//在此刷新的是屏幕上显示的cell的内容NSArray *visiblePaths = [self.tableView indexPathsForVisibleRows];//获取到的indexpath为屏幕上的cell的indexpath[self.tableView reloadRowsAtIndexPaths:visiblePaths withRowAnimation:UITableViewRowAnimationRight];}

3 图片圆角

3.1 layer.cornerRadius

imageView.layer.cornerRadius = imageView.frame.size.width/2.0;
// 隐藏边界
imageView.layer.masksToBounds = YES;

3.2 头像使用蒙版+贝塞尔曲线加圆角

CAShapeLayer *layer = [[CAShapeLayer alloc] init];UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.icon.width / 2, self.icon.height / 2) radius:self.icon.width / 2  startAngle:0 endAngle:M_PI * 2 clockwise:YES];layer.path = path.CGPath;
self.icon.layer.mask = layer;

3.3 stackoverflow

UIImageView *iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];[self.view addSubview:iconImage];// Get your image somehowUIImage *image = [UIImage imageNamed:@"image.jpg"];// Begin a new image that will be the new image with the rounded corners// (here with the size of an UIImageView)UIGraphicsBeginImageContextWithOptions(iconImage.bounds.size, NO, [UIScreen mainScreen].scale);// Add a clip before drawing anything, in the shape of an rounded rect[[UIBezierPath bezierPathWithRoundedRect:iconImage.bounds cornerRadius:10.0] addClip];// Draw your image[image drawInRect:iconImage.bounds];// Get the image, here setting the UIImageView imageiconImage.image = UIGraphicsGetImageFromCurrentImageContext();// Lets forget about that we were drawingUIGraphicsEndImageContext();

4 异步加载图片

第一种方法: SDWebImage的使用

[imageView sd_setImageWithURL:url completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {imageView.image = image;
}];

5 优化UITableViewCell高度计算

Tip
1. 使用不透明视图, 如非必要, 可以设置opaque为yes;
2. 图片的alpha尽量不设置透明度;
3. cellForRowAtIndexPath不要做耗时操作, * 读取文件/写入文件;* 尽量不要去添加和移除view;

iOS TableView性能优化相关推荐

  1. iOS tableView性能优化之异步排版和绘制渲染----YYText框架学习(YYTextAsyncLayer)

    YYWebImage源码分析 YYImage源码 YYModel源码解析 前言 这段时间针对设计架构,解耦以及性能优化相关的知识点看了不少,前两者可以看MVVM和AOP编程思路,最后一个是昨天看的,Y ...

  2. iOS tableview性能优化及分析

    1.最常用的就是cell的重用, 注册重用标识符 每次滑动cell时需要先去缓存池中寻找可循环利用的cell,如果没有则再重新创建cell 2.减少cell中控件的数量 view对象尽量缩减控件的数量 ...

  3. iOS app性能优化的那些事

     iPhone上面的应用一直都是以流畅的操作体验而著称,但是由于之前开发人员把注意力更多的放在开发功能上面,比较少去考虑性能的问题,可能这其中涉及到objective-c,c++跟lua,优化起来相对 ...

  4. iOS之性能优化·优化App界面的渲染与流畅度

    一.界面渲染流程 ① 渲染流程分析 计算机中的显示过程通常是通过 CPU.GPU.显示器协同工作来将图片显示到屏幕上,如下图所示: 苹果为了解决图片撕裂的问题使用了 VSync + 双缓冲区的形式,就 ...

  5. iOS app性能优化

    instruments   在iOS上进行性能分析的时候,首先考虑借助instruments这个利器分析出问题出在哪,不要凭空想象,不然你可能把精力花在了1%的问题上,最后发现其实啥都没优化,比如要查 ...

  6. ios 常见性能优化

    1. 用ARC管理内存 2. 在正确的地方使用reuseIdentifier 3. 尽可能使Views透明 4. 避免庞大的XIB 5. 不要block主线程 6. 在Image Views中调整图片 ...

  7. 深入浅出-iOS程序性能优化

    iOS应用是非常注重用户体验的,不光是要求界面设计合理美观,也要求各种UI的反应灵敏,我相信大家对那种一拖就卡卡卡的 TableView 应用没什么好印象.还记得12306么,那个速度,相信大家都受不 ...

  8. IOS UITableView性能优化

    1.关于UITableView性能的优化,很容易就让人想起UITableView的复用,那么除此之外呢?还有么有其他的方法能够优化用户的体验,或者说优化我们的设计的软件呢? 答案是:有! 一般我们在设 ...

  9. iOS之性能优化·优化App的启动速度

    抛砖引玉 启动是 App 给用户的第一印象,启动越慢用户流失的概率就越高,良好的启动速度是用户体验不可缺少的一环. 苹果是一家特别注重用户体验的公司,过去几年一直在优化 App 的启动时间,特别是去年 ...

  10. iOS显示性能优化过程讲解

    点我跳转原文地址 卡顿的原理 iOS系统界面滑动流畅性的保持主要是依靠CPU和GPU两大处理硬件间通力合作的结果,一个视图的显示需要先经过CPU创建.布局计算.对图片解码.文本绘制,然后CPU将计算的 ...

最新文章

  1. 《从零开始学Swift》学习笔记(Day 7)——Swift 2.0中的print函数几种重载形式
  2. 2015-12-18 学习心得
  3. 手工将python程序发布为exe执行程序 [转]
  4. Flink : Could not resolve substitution to a value: ${akka.stream.materializer}
  5. Django的基础操作总结
  6. 【对讲机的那点事】如何给4G全网通对讲机写号?
  7. MySQL结果集 数据查询(重点)
  8. ex is not shell_我使用过的Linux命令之exit - 退出当前shell
  9. 玩转基金(3)买卖基金
  10. 长焦拍照对比:小米10至尊纪念版和一加8 Pro、vivo X50 Pro+~~~~
  11. linux limits.conf 生效,linux修改limits.conf不生效
  12. stm32及LPC1768库函数串口输出重定向
  13. 用百度地图实现添加电子围栏并判断是否在范围内
  14. 你所不知道的网站外链高级操作策略
  15. a king读后感 love of the_一千零一夜英语读后感
  16. 外卖骑手的困局,算法不背这个锅 | Alfred数据室
  17. ptp协议服务器,ptp服务器 ieee1588 ieee 1588 1588对时
  18. 虚拟机下克隆CentOS后更改MAC地址
  19. linux14.10硬盘安装,U盘安装Ubuntu 14.10 Windows 7硬盘安装Ubuntu 14.10图文教程
  20. php判断bmi值,身体质量指数(BMI)能够“看”到肿瘤的发生

热门文章

  1. 取(2堆)石子游戏 (hdu2177)
  2. eval函数pythonmopn_pytorch:model.train和model.eval用法及区别详解
  3. hadoop文件的序列化
  4. MapReduce Shuffle详解
  5. python 自动打开登陆应用编码_Python+tkinter模拟“记住我”自动登录实例代码
  6. i.mx6 linux 占用率,i.MX6UL在Linux和Windows平台下SD启动卡测试步骤
  7. apache 添加虚拟机
  8. SpringBoot 启动过程,你不知道的秘密!
  9. 使用React构建精简版本掘金(三)
  10. Tomcat JMX