2013-05-30 58 views
0

以下是我的代碼。我可以從我的NSMutableArray文件加載所有圖像文件,但它沒有出現在我的屏幕上。我真的不知道爲什麼。如果任何人都可以幫助我,這將是非常好的。UIImage沒有顯示在我的屏幕上

在此先感謝.....

UIImageView *bannerImages; 
    CGRect bannerFrame; 

    for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++) 
    { 
     NSLog(@"photoCount: %d",photoCount); 

     bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)]; 

     NSString *photoString = [NSString stringWithFormat:@"%@",[imagesFileList objectAtIndex:photoCount]]; 

     NSLog(@"photoString are: %@",photoString); 

     bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]]; 

     bannerFrame = bannerImages.frame; 
     bannerFrame.origin.y = self.view.bounds.size.height; 
    } 

    [UIView animateWithDuration:1.0 
          delay:1.0 
         options: UIViewAnimationTransitionCurlDown 
        animations:^{ 
         bannerImages.frame = bannerFrame; 
        } 
        completion:^(BOOL finished){ 
         NSLog(@"Done!"); 
        }]; 

    [self.view addSubview:bannerImages]; 
    [bannerImages release]; 

這裏是我的日誌文件顯示:

2013-05-30 15:09:19.595 Yangon Guide Map[5035:15803] photoCount: 0 
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv01.png 
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 1 
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv02.png 
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoCount: 2 
2013-05-30 15:09:19.596 Yangon Guide Map[5035:15803] photoString are: adv03.png 
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoCount: 3 
2013-05-30 15:09:19.597 Yangon Guide Map[5035:15803] photoString are: edupro.png 
2013-05-30 15:09:21.598 Yangon Guide Map[5035:15803] Done! 
+0

檢查是否有任何其他子視圖阻止您的圖像視圖在層次結構中。 – Meera

+0

它不阻擋meera,如果我只加載一個具有確切名稱的圖像例如。 @「edupro.png」顯示我想顯示的位置。所以它不是等級問題,但感謝您的答案。 :) – Tin

+0

現在工作嗎?@Tin – Meera

回答

0

假設.png圖像是在App Bundle,可以更換

bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]];

bannerImages.image = [UIImage imageNamed:photoString]]; 

2.bannerFrame.origin.y = self.view.bounds.size.height; dosen't似乎幫助。

+0

Yap我已經試過bannerImages.image = [UIImage imageNamed:photoString]];但仍然相同,它沒有加載到我的圖像視圖:) – Tin

+0

圖像放置在哪裏? –

0

這個問題我認爲是,你已經填寫imageFileList與您在記錄時獲得的圖像名稱。

imageWithContentsOfFile是不應該得到這樣

圖像嘗試

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:photoString ofType:@"png"]]]; 

OR

可以使用imageNamed methiod這是非常strainght向前所以不是這個

bannerImages.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:photoString]]; 

使用此

bannerImages.image = [UIImage imageNamed:photoString]; 
0

你到底想幹什麼?因爲他們的很多代碼中的錯誤的...

1)你沒有創建的UIImage -imageWithContentsOfFile:就找不到你的文件,用:

bannerImages.image = [UIImage imageNamed:photoString]; 

bannerImages.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[imageNamed:photoString stringByDeletingPathExtension] ofType:@"png"]]; 

2)您爲陣列中的每個圖像創建一個新的UIImageView,但只將最後一個添加到您的根視圖。在你每個的UIImageView的添加循環:

for (int photoCount = 0; photoCount < [imagesFileList count]; photoCount++) 
{ 
    bannerImages = [[UIImageView alloc] initWithFrame:CGRectMake(0, 340, 320, 80)]; 

    // Snip ... 

[UIView animateWithDuration:1.0 
         delay:1.0 
        options: UIViewAnimationTransitionCurlDown 
       animations:^{ 
        bannerImages.frame = bannerFrame; 
       } 
       completion:^(BOOL finished){ 
        NSLog(@"Done!"); 
       }]; 

[self.view addSubview:bannerImages]; 
[bannerImages release]; 
} 

3)你bannerFrame計算似乎是錯誤的也一樣,因爲你是走出去的上海華界,所有的UIImageView將具有相同的幀。什麼是你的超級視圖,一個UIScrollView?您想做什麼 ?