I have this code that I use to download images from the server:
- (void) loadDataWithOperation {
NSURL *url = [NSURL URLWithString:@"http://myurl.com/testconnection.php"];
NSError* error;
NSString* connected = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
if (connected == NULL) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Error downloading gallery, please check network connection and try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
[self createBackButton];
} else {
NSLog(@"Connected - %@",connected);
NSLog(@"loadDataWithOperartion");
NSMutableArray *myURLS;
myURLS = [[NSMutableArray alloc] init];
NSLog(@"Here1");
for (int i = 0; i <= 4; i++){
NSString *tempString = [[NSString alloc] initWithFormat : @"http://myurl.com/GalleryImages/%djack1.jpg", i];
[myURLS addObject: [NSURL URLWithString:tempString]];
[tempString release];
}
NSMutableArray *myData;
myData = [[NSMutableArray alloc] init];
NSLog(@"Here2");
for (int i = 0; i <= 4; i++){
[myData addObject: [[NSData alloc] initWithContentsOfURL: [myURLS objectAtIndex:i]]];
}
NSMutableArray *myImages;
myImages = [[NSMutableArray alloc] init];
NSLog(@"Here3");
for (int i = 0; i <= 4; i++){
[myImages addObject: [UIImage imageWithData: [myData objectAtIndex:i]]];
}
NSArray *array = [[NSArray alloc] initWithArray:myImages];
[self setImages:array];
[myURLS release];
[myData release];
[myImages release];
[array release];
}
}
This code works as it always loads a given number of images on the server, in this case 4.
However, my problem is that if I wanted to increase the number of images to say 20, it would be a very long time to wait for the images to load and then display.
Basically, I would like to upload 5 images from the loading screen, and then the remaining 15 downloads until the user can view the first 5. Can someone give me an idea of how I will do this?
When images are downloaded, they are scaled to the iphone screen size and placed in the UIScrollView for viewing.
Thank,
Jack