2011-03-16 23 views
0

我使用ImageDemo模板,它工作得很好,如果我從包中的圖像編碼,但是當我嘗試從我的應用程序中創建的目錄中加載它們時,我沒有運氣。iPad AQGridView不顯示我的UIImages不在捆綁

代碼:我使用的拉我知道的作品,因爲我在我的應用程序等地遍使用的圖像數據,我檢查了無當我設置的財產

- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index 
    { 
     static NSString * PlainCellIdentifier = @"PlainCellIdentifier"; 

     AQGridViewCell * cell = nil; 
     ImageDemoGridViewCell * plainCell = (ImageDemoGridViewCell *)[aGridView dequeueReusableCellWithIdentifier: PlainCellIdentifier]; 
     if (plainCell == nil) 
     { 
      plainCell = [[[ImageDemoGridViewCell alloc] initWithFrame: CGRectMake(0.0, 0.0, 200.0, 150.0) 
                 reuseIdentifier: PlainCellIdentifier] autorelease]; 
      plainCell.selectionGlowColor = [UIColor lightGrayColor]; 
     } 
     NSString *fileName = [NSString stringWithFormat:@"%@/%@_tn.jpg",[manufacturerID stringValue], [[[self.collectionItems objectAtIndex:index] valueForKey:@"PhotoName"] stringByReplacingOccurrencesOfString:@" " withString:@"%20"]]; 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsPath = [paths objectAtIndex:0]; 
     NSString *savePath =[documentsPath stringByAppendingPathComponent:fileName] ; 
     NSData *imageData = nil; 
     BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:savePath]; 
     if (fileExists) { 
      imageData = [NSData dataWithContentsOfFile:savePath]; 

     } else { 
      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"NoImageAvailableThumbNail" ofType:@"png"]; 
      imageData = [NSData dataWithContentsOfFile:filePath]; 
     } 

UIImage *myImage = [UIImage imageWithData:imageData]; 
    NSLog(@"%@", myImage); 
    if (myImage==nil) { 
     NSLog(@"NO IMAGE"); 
    } 
    plainCell.image = myImage;  

     cell = plainCell; 

     return (cell); 
    } 

我的代碼AQGridViewCell:

- (void) setImage: (UIImage *) anImage 
{ 
    _imageView.image = anImage; 
    [self setNeedsLayout]; 
} 

回答

1

我沒有在您的示例中看到一個無UIImage檢查。你確定它被正確加載?嘗試在一行上創建圖像並將其設置在另一行上,以便您可以看到它正在調試器中創建。作爲參考,我在Kobo應用程序中做了一些類似於緩存的書籍封面圖片,這很有效。不同的是,我使用C方法從PNG文件加載UIImage。像UIImageFromPNGData()這樣的東西,離開我的頭頂(現在不好意思回覆iPhone)。

我唯一能想到的其他事情是檢查圖像視圖是否由於某種原因被隱藏。在調試器中打印它應該告訴你,以及它的大小,佈局等。

+0

非常感謝你的回答,我添加了日誌記錄,並且我絕對得到一個圖像:但他們只是不' t顯示。我一定在某個地方做了一些愚蠢的事情 - 我會繼續尋找和感謝。 – Slee 2011-03-16 16:14:11

+0

仍然堅持這個,我知道UIImage被創建並通過 - 我將它們添加到主視圖,因爲它作爲測試循環通過,他們肯定會加載。我可以從其他地方加載包含在該包中的圖像,包括來自URL的圖像。如果你能想到其他的東西,我會很感激 - 謝謝你的幫助。 – Slee 2011-03-21 22:26:49

+0

要檢查的一件事就是圖像視圖的框架不是空矩形(即寬度/高度爲0.0)。它應該在'-layoutSubviews'中更新,因此請先在那裏檢查。此外,請檢查返回的UIImage是否有空或零大小(0.0x0.0),因爲這可能會導致相同類型的問題。 – 2011-03-21 23:57:32