2011-08-18 3 views
0

配列から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]; 
+0

どのようにfileArrに記入しますか?可能であれば、コードを投稿してください。 –

+0

あなたはすべての反復であなたのイメージビューを削除しています。なぜそれは最後のものだけを表示するための責任ですか? –

+0

- (NSArray *)listAndPopulateFileArray:(NSString *)jfn1 { \t \t NSFileManager * fileManager = [NSFileManager defaultManager]; \t NSString * jFolder = [NSHomeDirectory()stringByAppendingPathComponent:jFolder]; \t \t NSArray * imageList = [ファイルマネージャーcontentsOfDirectoryAtPath:jobFolderエラー:nil]; \t \t返信imageList; \t } – Carissa

答えて

2

あなたがforループであなた

[scrollView addSubview:image]; 

前に必ず

[image removeFromSuperview]; 

あるため。

どうやって最後の画像を表示できないのですか?

+0

'私はuiimageviewに表示されている画像を削除したいと思います。 – Carissa

+0

'addSubView'の前に' removeFromSuperview'を呼び出す必要はありません。なぜなら、 'addSubView'を呼び出すと、そのサブビューは別のビューのサブビューとして追加される前に自動的にその前のスーパービューから削除されるからです。 – EmptyStack

+0

表示する画像が10枚あれば、10枚の画像ビューを作成する必要があります。これらのimageViewsの位置を自分で設定する必要があります。そうでない場合は、互いにカバーされます。 – xuzhe

関連する問題