iOS UITableViewCell优化 [英] iOS UITableViewCell Optimization

查看:114
本文介绍了iOS UITableViewCell优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个包含自定义UITableViewCells的UITableView。滚动非常迟缓和滞后,我需要解决这个问题。

In my app I have a UITableView that contains custom UITableViewCells. Scrolling is very sluggish and laggy, and I need to resolve this.

每个单元格包含5-6个标签,几个按钮和一个图像。

Each cell contains 5-6 labels, a few buttons, and an image.

我有一个单元格的xib,我放置按钮,标签和图像视图,但我在cellForRowAtIndexPath中设置了所有图像。要加载图像,我使用[UIImage imageNamed:@],我读到的图像更适合优化。我也是重复使用的单元格。

I have a xib for the cell, where I place the buttons, labels, and image view, but I set all of the images in cellForRowAtIndexPath. To load the images I use [UIImage imageNamed:@""], which I read is better for optimization. I am also the reusing cells.

我还发现,即使我注释掉并且没有设置图像,表格仍然是滞后的,只有标签设置为文本。

I also found that even if I comment out and do not set the images, the table still is laggy, with just the labels set with text.

有没有人对如何拥有一个相当复杂的表格单元格有任何建议,同时仍然具有良好,流畅的性能?将自定义单元格作为xib阻碍性能?

Does anyone have any suggestions on how to have a rather complex table cell while still having good, smooth performance? Is having the custom cell as a xib hinder performance?

推荐答案


  1. 确保你真的正在重复使用细胞。确保您使用的单元格
    标识符在界面构建器中的 UITableViewCell
    的XIB中设置。

  1. Make sure you really are reusing cells. Make sure that the cell identifier you are using is set in the XIB of the UITableViewCell in interface builder.

在子视图中使用较少的透明度。如果可能,请进入标签并确保其背景与单元格背景的背景相匹配。

Use less transparency in your subviews. If at all possible, go into your labels and make sure their background matches with that of the background of the cell.

检查未经优化的代码。例如,如果您正在显示格式化日期,并且每次 tableview创建 NSDateFormatter 的实例:cellForRowAtIndexPath:被叫,这将真正困扰你的应用程序。

Check for unoptimized code. For example, if you're displaying a formatted date and are creating an instance of NSDateFormatter each time tableview:cellForRowAtIndexPath: is called, this will really bog down your app.

使用带有时间和核心动画模块的仪器来查找大部分时间花在哪里。最终,这些可以揭示真正的性能问题所在。

Use Instruments with the Timing and Core Animation modules to find where the bulk of your time is spent. Ultimately, these can reveal where the true performance problem lies.

这篇关于iOS UITableViewCell优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆