代码是一个包含大量图像的简单集合视图 我运行它并且Xcode没有争论任何事情,但模拟器在运行应用程序后显示黑屏。
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return recipePhotos.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier =@"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
// Configure the cell
UIImageView * recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image=[UIImage imageNamed:[recipePhotos objectAtIndex:indexPath.row]];
return cell;
}
答案 0 :(得分:0)
答案 1 :(得分:0)
如果您不想要黑色背景,则必须设置
collectionView.backgroundColor = [UIColor clearColor];
然后你必须注册单元格
UINib *cellNib = [UINib nibWithNibName:@"yournibname" bundle:nil];
[collectionView registerNib:cellNib forCellWithReuseIdentifier:@"cell"];
两者都需要在viewDidLoad方法中实现