将数组中的图像显示到 UIImageView
我试图将图像从数组显示到 uiimageview,但它只显示最后一个图像。有什么建议吗?
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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你总是
在你之前
因为在 for 循环中
。怎么可能不只显示最后一个imageView呢?
Because you are always
before you
in the for loop.
How could it not be only showing the last imageView?