开发者

Asynchronous image loading

I'm developing an iPad 开发者_如何学编程application that's similar to the built in Photos app. I've used NSThread detachNewThreadSelector to load the image and managed to cut down loading time from 12s to 6s, still not up to my expectation. I suspect that, let say there are 20 images in a folder, 20 threads are created to load the images. Now I'm thinking on limiting it to 5 threads at a time, and the next group of threads should start only after the previous 5 images are loaded. Can someone enlighten me how to do this? Thanks a lot!


I won't be long : you should definitively have a deep look at this example from Apple. You will see the light.


This sounds like a perfect task for NSOperationQueue.

First, you create and configure an NSOperationQueue, and save it in an ivar or global variable. Then, instead of using detachNewThreadSelector:toTarget:withObject:, create an NSInvocationOperation with the same selector, target, and object and add it to the queue. The queue will handle starting the operations on a pool of background threads as threads become available.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜