IOS中如何提高UITableView的性能?

最近看了一篇关于如何提高UITableView性能的文章,英文原版的地址:https://medium.com/ios-os-x-development/perfect-smooth-scrolling-in-uitableviews-fd609d5275a5#.jet1gcbax,看完之后将重要的内容总结如下:

1,对于:

tableView:cellForRowAtIndexPath:

Don’t perform data binding at this point, because there’s no cell on screen yet. For this you can use tableView:willDisplayCell:forRowAtIndexPath:method which can be implemented in the delegate of UITableView. The method called exactly before showing cell in UITableView’s bounds

不要在这个方法里面给cell赋值,因为这个时候Cell还没有出现。对此,你可以在tableView:willDisplayCell:forRowAtIndexPath:中进行,这同样是UITableView的一个代理方法,这个方法在Cell即将在UITableView的范围中显示的时候调用。

2. 在返回Cell的高度时候

I recommend not using even complex math calculations on your way to define further height of a cell, only addition, subtraction, multiplication and division (if possible).

在决定即将显示的Cell的高度的时候,建议不要使用复杂的计算,如果可能的话仅用加减乘除;

3.用AutoLayout自动适配Cell的高度怎样?

如果子视图少的话是可以的,如果子视图多的话,使用AutoLayout,性能也会减少很多的:And more subviews you have, less quickly AutoLayout works.

4. Perform code optimizations to achieve balance of loading CPU & GPU. You should clearly know which part of rendering must be done by GPU, and which one — by CPU for keeping balance.

 将代码最优化,以达到CPU和GPU使用的平衡,你应该提前知道哪里一定要使用GPU进行渲染,哪里使用CPU来保持二者的平衡;

5. We can perform rendering at CPU by using CoreGraphics operations in drawRect: method of UIView by this way:

我们可以选择CoreGraphics利用CPU在drawRect方法中,进行渲染,实例代码如下所示

转载于:https://www.cnblogs.com/Mike-Fighting/p/5068654.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值