开发者

loading 60 images locally fast is it possible...?

when my app starts it loads 60 images at a time in UIImageView and it also loads a background music.

in simulator it works fine but in IPAD it crashes..

-(void)viewDidLoad
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

//img.animationImages = [[NSArray arrayWithObjects:

MyImages = [NSArray arrayWithObjects:
                       //[UIImage imageNamed: @"BookOpeningB001.jpg"],...... B099,nil];


//[NSTimer scheduledTimerWithTimeInterval: 8.0 target:self selector:@selector(onTimer) userInfo:nil repeats:NO];

img.animationImages = MyImages;
img.animationDuration = 8.0; // seconds
img.animationRepeatCount = 1; // 0 = loops forever
[img startAnimating];
[self.view addSubview:img];
[img release]; 

[pool release];

//[img performSelector:@selector(displayImage:) ];

//[self performSelector:@selector(displayImage:) withObject:nil afterDelay:10.0];
[s开发者_运维问答elf performSelector: @selector(displayImage) withObject: nil afterDelay: 8.0];
}


-(void)displayImage {

SelectOption *NextView = [[SelectOption alloc] initWithNibName:nil bundle:nil];

[self presentModalViewController:NextView animated:NO];
[NextView release];
}

Am i doing anything wrong ? Is there any other alternative to load the local images faster in UIImageView !


I was doing something similar. Even if you quit all of the other apps on your iPad and manage to get it to run it will crash on you randomly.

I fixed this by preload very small (like 5 or 6 k) gif images. Then when my user entered an area where the big image needed to be seen I loaded the full res pic as a jpg and released the object as soon as they were done with it.

Now my app no longer has an issue on the simulator or the device and I do not have to have the user close everything.


If something crashes on the device but not on the simulator 9/10 times is your app has received a few memory warnings and forced to quit.

This Theory can be tested easily in two ways. First is to Log something to console in the appDelegates Memory Warning event method and secondly, when you run the app in the simulator, open the activity monitor and view the memory usage of the app by name.

The golden rule is that you should use as low a res of an image that you can get away with.

Rohit, is right in saying that pre-loading smaller images is one way to solving this problem provided that your not leaking, but this solution is only suitable for certain apps.

Lazyily loading media is generally how you should do this. There is no reason why you should have to load any more than 3 full res (full screen) images at any one time in an iPad app if you implement a decent memory efficient design.

In the case where you are doing something like a slide show for exmaple, you should be only be loading the focused image + 1 image each side into memory, destroying out of scope images as you go. Using a UIScrollView makes this easy with events that fire when scrolling has started, occurring and ended.

Speed improvements can be made by using CATitledLayer's, mutithreading any image tasks you can (GCD and blocks) (getting UIKit contexts are now thread safe too).

Good luck there are plenty of examples of all of these things accessible via the apple documentation or a quick search.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜