Reputation: 1
I am trying to display images from the array to the uiimageview, but it only shows the last image. Any advise?
for (int i = 0; i < [fileArr count]; i++)
{
NSArray *fileNameArr = [[fileArr objectAtIndex:i] componentsSeparatedByString:@"."];
check=line;
NSString *msg = [textView.text stringByAppendingString:[NSString stringWithFormat:@"Opening image: %@\n",[fileArr objectAtIndex:i]]];
[textView performSelectorOnMainThread:@selector(setText:) withObject:msg waitUntilDone:NO];
line=line+1;
[image removeFromSuperview];
[image release];
image = nil;
//specify the image path, open the image file with UIImage library
NSString *imagePath = [NSString stringWithFormat:@"%@/%@",jfn1,[fileArr objectAtIndex:i]];
NSString *imageFile = [NSHomeDirectory() stringByAppendingPathComponent:imagePath];
NSString *pathExtension = [imageFile pathExtension];
NSLog(@"----------------------------");
NSLog(@"ImageFile: %@\n",imageFile);
NSLog(@"File Extention: %@\n", pathExtension);
NSLog(@"Interger value: %i\n",i);
UIImage *myImage = [UIImage imageWithContentsOfFile:imageFile];
NSLog(@"Image Width: %f", myImage.size.width);
NSLog(@"Image height: %f", myImage.size.height);
image = [[UIImageView alloc] initWithImage:myImage];
image.contentMode = UIViewContentModeScaleAspectFit;
[scrollView addSubview:image];
Upvotes: 0
Views: 901
Reputation: 5120
Because you are always
[image removeFromSuperview];
before you
[scrollView addSubview:image];
in the for loop.
How could it not be only showing the last imageView?
Upvotes: 2