2011-08-05 34 views
0

我試圖改變imageview中的圖像,但我似乎無法做到這一點。 我的代碼如下所示爲每個要顯示的圖像創建一個新的子視圖。然而,圖像只是重疊,並顯示在不應該是結束的重疊圖像。如何刪除重疊的uiimageview?

.M:

for (int i = 0; i < [imageArr count]; i++) { 

     NSArray *imageNameArr = [[imageArr objectAtIndex:i] componentsSeparatedByString:@"."]; 

      check=line; 
      NSString *msg = [textView.text stringByAppendingString:[NSString stringWithFormat:@"Opening image: %@\n",[imageArr objectAtIndex:i]]]; 

      [textView performSelectorOnMainThread:@selector(setText:) withObject:msg waitUntilDone:NO]; 

       line=line+1; 

      NSString *imagePath = [NSString stringWithFormat:@"%@/%@",jName,[imageArr objectAtIndex:i]]; 
      NSString *imageFile = [NSHomeDirectory() stringByAppendingPathComponent:imagePath]; 
      NSLog(@"------------------------------"); 
      NSLog(@"ImageFile: %@\n",imageFile); 
      NSLog(@"Interger value: %i\n",i); 

      UIImage *myImage = [UIImage imageWithContentsOfFile:imageFile]; 
      UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage]; 
      imageView.contentMode = UIViewContentModeScaleAspectFit; 
      [scrollView addSubview:imageView]; 
      [imageView release]; 
..... 
..... 
} 

如何單獨顯示圖像,沒有重疊?

回答

2

,就把這行出來的for循環:

UIImageView *imageView = [[UIImageView alloc] initWithImage:myImage]; 
    [scrollView addSubview:imageView]; 

,並用它喜歡:

UIImageView *imageView = [[UIImageView alloc] init]; 
    [scrollView addSubview:imageView]; 

及用途:

[imageView setImage:[UIImage imageWithContentsOfFile:fullImgNm]]; 

在for循環中。

0

您創建imageview超出循環並更改循環內該imageview的來源(圖像)。 您在循環開始之前做到這一點,

UIImageView *imageView = [[UIImageView alloc] init]; 
[scrollView addSubview:imageView]; 

,並添加這樣的圖像內循環,

[imageView setImage:[UIImage imageWithContentsOfFile:imageFile]];