如何将图像加载到iPhone系统缓存中? [英] How can I load images into the iphone system cache?

查看:66
本文介绍了如何将图像加载到iPhone系统缓存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableView里面有一些大图像.我正在努力改善非常生涩的滚动性能.如果我使用ImageNamed加载图像,则滚动起初会比较混乱,但是在查看图像后,滚动会很平滑.我知道ImageNamed将图像添加到系统缓存中,所以我的问题是:是否可以在查看图像之前将其预加载到系统缓存中?

I have a tableView with some large images in it. I'm struggling to improve the very jerky scrolling performance. If I use ImageNamed to load the images, scrolling is jerky at first, but after the images are viewed, scrolling is smooth. I know ImageNamed adds the images into the system cache, so my question is: is it possible to pre-load the images into the system cache before they are viewed?

我试图通过将以下代码添加到我的viewDidLoad方法中来尝试:

I've tried by adding the following code to my viewDidLoad method:

for (int i = 0; i < appDelegate.detailSectionsDelegateDict.count; i++) {
         NSString *imageString = [NSString stringWithFormat:@"%@",[[appDelegate.detailSectionsDelegateDict objectAtIndex:i] objectForKey:@"MainTrackImage"]];
        NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
        UIImage* theImage;
        theImage = [UIImage imageNamed:imageString];
         [imageCacheArray insertObject:theImage atIndex:i];
}

然后我在CellForRowAtIndexPath方法中从imageCacheArray绘制正确的图像.但是结果仍然是滚动滚动.

I then draw the correct image from the imageCacheArray in my CellForRowAtIndexPath method. But the result is still jerky scrolling.

谢谢!

推荐答案

使用图像(尤其是大图像)进行平滑滚动的表格视图并不是您想的那么简单.使用[UIImage imageNamed:]加载一堆图像会很快导致跳板杀死您的应用程序,因为它开始超过内存容量.看一下今年WWDC上的Core Animation 会议视频,特别是会议425,实践中的核心动画,第2部分"他们涵盖了这个确切的主题,并且做得很好.如果您使用开发者帐户登录,也可以获取相关的源代码.

Getting a table view with images (especially large ones) to scroll smoothly is not as trivial as you might think. Loading up a bunch of images with [UIImage imageNamed:] will very quickly cause springboard to kill your app as it starts to exceed memory capacity. Take a look at the Core Animation session videos from this year's WWDC, specifically look at session 425, "Core Animation in Practice, Part 2" They cover this exact topic and it's very well done. You can also get the relevant source code if you sign in with your developer account.

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

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