UIImage 性能和 UITableViews 优化
我正在使用多个图像来设计 UITableViewCells 的样式,我想确保我做的事情正确,首先是为了确保良好的内存管理,其次是为了确保事情尽可能快(我遇到了缓慢的问题)滚动!)。
我知道使用 [UIImage imageNamed:] 会缓存图像以提高速度,那么可以使用它来获取我的所有图像吗?还是每个 UITableViewController 只调用一次并将图像存储为实例变量,为我的所有单元格重用相同的 UIImage 对象?
我在表格和单元格中使用透明的 PNG 和清晰的彩色视图来获得我想要的外观。是否有任何提示可以确保它尽快渲染以确保表视图滚动平滑?目前我只有大约 10 行(单元格),而且已经相当缓慢了。我正在使用获取的结果控制器来获取我的数据,所以我认为这不会导致它。
非常感谢,
迈克尔
I'm using several images to style UITableViewCells and I want to make sure I'm doing things correctly, firstly to ensure good memory management, and secondly to make sure things are as fast as possible (I'm having troubles with the sluggyness of the scrolling!).
I know that using [UIImage imageNamed:] will cache the images for speed, so is it okay to use that for getting all my images? Or is it better to only call that once per UITableViewController and store the image as an instance variable, reusing the same UIImage object for all my cells?
I'm using transparent PNGs and clear coloured views in my table and cells to get the look I'm going for. Are there any tips on ensuring it renders as quick as possible to make sure the table view scrolling is smooth? At the moment I only have about 10 rows (cells) and it's already quite sluggish. I'm using a fetched results controller to get my data so I don't think it could be that causing it.
Many thanks,
Michael
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用透明度的秘诀是不要。如果您有多个重叠元素,请查看是否有某种方法可以预渲染透明效果 - 这几乎是最重要的,这会破坏表格滚动性能。
另一个重大打击是如果您没有正确地重复使用细胞。
获取的结果控制器不应该采取任何措施来减慢速度。您可以尝试使用 Instruments 来确保......
The tip to using transparency is don't. If you have multiple overlapping elements see if there is some way to pre-render the transparent effect - that more than almost anything, is what will kill table scrolling performance.
The other big hit is if you do not properly reuse cells.
The fetched results controller should do nothing to slow things down. You could try using Instruments to make sure of that...
我想最好为所有单元格重用 UIImage 实例,这样您就可以保留它并确保在出现内存警告时不会释放它,这是您没有 [UIImage imageNamed:] 的保证的缓存。另外,保持平滑的一个技巧是确保没有重叠的视图,尤其是透明的视图。
I guess it's better that you reuse the UIImage instance for all your cells, this way you can retain it and make sure it isn't released in case of a memory warning, a guarantee that you don't have for [UIImage imageNamed:]'s cache. Also, a tip for keeping it smooth is to make sure you don't have overlapping views, especially transparent ones.
如果您在所有表格单元格上使用相同的图像,那么最好通过 +(UIImage)imageNamed:(NSString*)inName API 从系统图像缓存中获取图像。
尝试使用 UITableViewCell 的 dequeueReusableCell API 来获取每个单元格。如果返回 nil,则仅创建一个新的单元格对象。
如果您的表视图颜色是透明(UIClearColor),则将表视图的不透明属性设置为NO。
如果
If you are using the same image on all of your table cells then it is good to get the image from system image cache by +(UIImage)imageNamed:(NSString*)inName API.
Try to get each of your cell by making use of dequeueReusableCell API of UITableViewCell. If this returns nil then only create a new cell object.
If your table view color is transparent(UIClearColor) then set the opaque property of the table view to NO.