Including many images in iPhone application without slowing down xcode
I have an application where I query a database and load a large number of small images. Currently, I add images as a resource in my iPhone project in xcode (by dragging it into the resources folder under the approp开发者_如何学JAVAriate group). However, I am attempting to now add feature which adds an additional 8000 images to the project.
After adding these images, I notice that interface builder become extremely slow to load the image previews. It results in IB being extremely unresponsive, using a lot of CPU. If I disable syncing with xcode it doesn't load the image previews at all.
Is there any way to include and reference these images in an efficient way that won't slow down the UI. I'd like for my UI not to slow down based on the number of images in my project.
I have developed an app containing far more images, with not a single problem (apart from the build/packaging stage, which takes ages at over 1 Gb of data).
The key is to add the folder containing the images as a "folder reference", not as a group and individual items. When accessing the images, you do have to perform some more magic than [UIImage imageNamed:@"..."]
.
You get to the path of the images using
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"yourdirectory"]
and adding filenames (and/or reading directory contents, naturally)
ps. this assumes that you don't actually use the images in Interface Builder.
oh, and one more tip: while developing, once you installed the app the first time, you can remove the images from your app in xcode. As long as you don't remove the app from your device, the images will still be on the device, available to your code, but building and installing will be way faster.
That is a HUGE number of images to add. Naturally, Xcode is going to take a while to process all of them, initially on the first build.
If you do not clean your builds, or delete your app from the Simulator, then Xcode should process them faster if they do not change.
As for the User Interface slowing down, try not to load all of the images in 1 instance; like having a table with 8000 images, theres just no way to slow that down, even in the simulator.
精彩评论