我有一个继承自UIViewController的类,可以通过UICollectionView的出口调用它'controller'。 从UICollectionCell继承的类允许将其称为“A”,而另一个来自UIImage的类称为“B”,A具有B的出口
我在'controller'中编写了以下代码:
- (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 :(得分:0)
initWithContentsOfFile:
需要文件路径,而不是URL
。如果您使用的是URL
,则应该使用initWithContentsOfURL:
NSURL
(而不是NSString
),因此您必须通过[NSURL URLWithString: imageUrl]
}}