简体   繁体   中英

How to load images in UIImage array from an online directory and store them in the App

I want to load multiple images when my app starts from a website (ie all images in http://hello.com/images/ which are named 1.png, 2.png, 3.png..) , so that the images can be used anywhere in the program without needing to reload them every time I want to access them.

Can I simply create a class that holds a static NSArray and fill it at the beginning, to then create an instance of this class whenever I need the images or is there a better way to do it?

Right now, I am loading the images with the following code:

UIImage *image =[[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://hello.com/images/%@.png,item]]]];

I want to make the app as efficient as possible, so I am concerned about the creation of multiple objects making it very demanding.

Thanks

You can try downloading the images asynchronously in a separate thread when the application starts and use it later.

Here is the SO question and answer where the poster uses a custom class to download the images in the background asynchronously.

Try this for efficient download of images and UI also will not be blocked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM