[英]Display images from array to UIImageView
I am trying to display images from the array to the uiimageview, but it only shows the last image. 我试图将数组中的图像显示到uiimageview,但它只显示最后一张图像。 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];
Because you are always 因为你永远
[image removeFromSuperview];
before you 在你面前
[scrollView addSubview:image];
in the for loop. 在for循环中。
How could it not be only showing the last imageView? 怎么可能不只是显示最后一个imageView?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.