iOS中的图像缓存 [英] Image caching in iOS

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

问题描述

如果我这样做

rowBackground = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bottomCell2.png"] 

在应用程序的整个生命周期中缓存图像还是在我每次执行该指令时(在其他视图或应用程序的一部分中)重新加载并重新缓存图像?

the image is cached for the entire life cycle of the app or reloaded and recached everytime I execute that instruction (in other views or part of the app)?

我在应用程序的每个表视图中执行此操作.有效率吗?

I do that in every tableview of my app. Is it efficient?

提前谢谢!

推荐答案

作为+imageNamed:的引用:

此方法在系统缓存中查找具有以下内容的图像对象: 指定名称,并返回该对象(如果存在).如果匹配 图像对象尚未在缓存中,此方法将加载图像 指定文件中的数据,将其缓存,然后返回 结果对象.

This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

缓存是有效的,但会占用内存.如果您的表格视图包含大量图像,则内存可能会耗尽.因此,您可以考虑+imageWithContentsOfFile:或其他类似方法来加载图像.

Cache is efficient, but eats memory. If your table view contains large amount of images, the memory may burn up. So you may consider +imageWithContentsOfFile: or other similar methods to load image.

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

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