簡體   English   中英

將數組中的圖像顯示到UIImageView

[英]Display images from array to 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];

因為你永遠

[image removeFromSuperview];

在你面前

[scrollView addSubview:image];

在for循環中。

怎么可能不只是顯示最后一個imageView?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM