Search code examples
iosxcodemultithreadingipadphoto-gallery

Load "Loading" image before laoding Image from server?


I am new to iOS development so please bear with me. I am trying to create a basic photo gallery but ran into a problem. When I started out with the project I just included all the images in my project. Now after having a lot more images(400+) I started loading them from a server. I made an array of images using the following line of code:

[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.testsite.com/testPic.png"]]]

Obviously making the user wait for an array of 400+ images to load from a server is unacceptable.

So my question is if I included one image in my project that said something like "Loading", how could I display that image until the actual image loaded from the server?

I'm making a basic grid-style photo gallery using a table-view and scroll-view. It loads up a few rows of small(thumbnail) images and when you click one it makes it full screen.

I'm using Xcode 4.3, ARC, and storyboards if that helps!

Sorry if this is confusing!

-Shredder2794


Solution

  • The simplest way of doing this is to use AFNetworking, which provides setImageWithURL:placeholderImage: in a category on UIImageView (also a method with success/failure handlers).