即時通訊嘗試從網絡載入一組圖像並將其顯示在屏幕上的集合視圖中。下面是我的代碼無法使用objectAtIndex屬性
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.layer.cornerRadius = 5;
NSURL *url = [NSURL URLWithString:
@"http://elatewiki.org/images/thumb/Google.png/120px-Google.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
//recipeImageView.image = [UIImage imageNamed:[recipePhotos objectAtIndex:indexPath.row] ];
recipeImageView.image = [UIImage imageWithData: [NSData dataWithContentsOfURL:recipPhotoUrl[0] ]];
return cell;
}
,但我不得不使用objectAtIndex:indexPath.row
屬性與imageWithData沿着這樣的圖像可以刷卡。有什麼辦法通過我可以使用objectAtIndex:indexPath.row以及NSData dataWithContentsOfURL
?
凡被定義'recipePhotos'和'recipPhotosUrl'? – Larme
recipePhotos包含靜態圖像文件的名稱 –
recipePhotoUrl包含動態獲取照片的所有URL。 –