2013-04-05 158 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