I’m trying to load 5 images at the same time,for them put it on the view and change the image every 5 sec(change between the current 5)
I create the current a class wich is called when the viewdidload and starts the timer,the method to load all images is this:
-(NSMutableArray *)getAllPhotos
{
NSMutableArray * photosArray = [[NSMutableArray alloc]init];
NSString * pic0 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/0.png"];
NSString * pic1 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/1.png"];
NSString * pic2 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/2.png"];
NSString * pic3 = [NSString stringWithFormat:@"http://74.53.32.202/~ltashiro/public/Servidor/Images/3.png"];
NSURL *image0 = [NSURL URLWithString:pic0];
NSURL * image1 = [NSURL URLWithString:pic1];
NSURL * image2 = [NSURL URLWithString:pic2];
NSURL * image3 = [NSURL URLWithString:pic3];
NSMutableArray * arrayURL = [[NSMutableArray alloc]init];
[arrayURL addObject:image0];
[arrayURL addObject:image1];
[arrayURL addObject:image2];
[arrayURL addObject:image3];
for (int i = 0; i<4; i++)
{
NSData * imageData = [[NSData alloc]initWithContentsOfURL:[arrayURL objectAtIndex:i]];
Photo * aPhoto = [[Photo alloc]init];
aPhoto.photoID = (i+1);
aPhoto.photo = [[UIImage alloc]initWithData:imageData];
[photosArray addObject:aPhoto];
[aPhoto release];
[imageData release];
}
return photosArray;
}
But sometimes the appcrashs on launch,theres any other solution abordation to it?
I was searching for the problem posted here. I found a solution here:
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
Didn’t test it yet though.