2013-04-05 210 views
0

我有一個繼承自UIViewController的類可以通過UICollectionView的出口調用它'controller'。 從UICollectionCell繼承的類可以調用它的「A」,另一個來自的UIImage讓稱之爲「B」,A具有B的出口爲什麼我的圖像不顯示

我在「控制器」寫以下代碼:

- (UICollectionViewCell *)collectionView:(UICollectionView *)p_collectionView cellForItemAtIndexPath:(NSIndexPath *)p_indexPath 
{ 
    UICollectionViewCell* cell = [self getUICollectionViewCellFromCollectionView:p_collectionView AtIndexPath:p_indexPath]; 
    if([cell isKindOfClass:[ImageCollectionViewCell class]] == YES) 
    { 
     //draw the image inside the view 
     ImageCollectionViewCell* imageCell = (ImageCollectionViewCell*)cell; 
     NSString* imageUrl = self.objectToShow.imagesURL[p_indexPath.item]; 
     UIImage* currentImage = [[UIImage alloc] initWithContentsOfFile:imageUrl]; 
     imageCell.imageView.image = currentImage; 
    } 

    return cell; 
} 

一切正常初始化,但圖像不顯示,我不知道這是爲什麼。

有人可以幫助我嗎?

+0

你設置了UICollectionViewFlowLayout嗎? – 2013-04-05 05:13:14

回答

0

initWithContentsOfFile:需要文件路徑,而不是URL。如果您使用的是URL,則應該使用initWithContentsOfURL:,這需要NSURL(而不是NSString),因此您必須通過[NSURL URLWithString: imageUrl]

+0

你是正確的,我應該改變我的參數名稱,因爲我傳遞文件路徑 – 2013-04-05 02:48:37