views:

45

answers:

2

Currently I am retrieving a bunch of images from the internet and scaling them and then displaying them on my view.

The problem is I am doing it in the viewDidLoad method - so when the user taps they have to actually wait for this processing to happen and then the view is shown which causes a slight delay.

Is there anyway I could show the view and then somehow spark off the loading of the images AFTER the user has the view in front of them - similar to how a web page loads?

- (void)configureImages
{
   if ([currentHotel.hotelImages count] > 0)
   { 
     imageView1.image = [self getScaledImageFromURL: [currentHotel.hotelImages objectAtIndex:0]];
     imageView2.image = [self getScaledImageFromURL: [currentHotel.hotelImages objectAtIndex:1]];
     imageView3.image = [self getScaledImageFromURL: [currentHotel.hotelImages objectAtIndex:2]];        

   }
}
+1  A: 

Consider NSOperation/NSOperationQueue, discussed in the Concurrency Programming Guide. There are several links to examples here.

Joshua Nozzi
A: 

Apps should use the asynchronous networking APIs for all networking to avoid blocking the user experience. It's best to avoid adding threads (such as happens when you use NSOperationQueue) for tasks like networking where the OS already provides async alternatives.

Apple supplies the async NSURLConnection, which works well but is a bit tedious to use. You can add a simple wrapper like gtm-http-fetcher which reduces async fetches to a single line with a callback when the load has finished. That will let you start all the loads in your viewDidLoad: method without stalling the user interface.

grobbins
You are a God among men!
TheLearner