Instead of UICollectionView a black screen is displayed

懵懂的女人 提交于 2019-12-04 22:21:15

You are configuring correctly the CollectionView, just that you forgot the color of the label :)

    [self.label setTextColor:[UIColor whiteColor]];

Hope it helps!

You need to manually set the background color of the collection view in the storyboard.

By default it is black (although not showing that in the storyboard editor)

I had the same issue. The black screen seems to be an indicator of no data available with collection view to display. Try changing the background color of the collection view, if that changed color got to display, your collection view is working. And then add some imageview to the collection view with tag (Ex. give a value 100 with the tag value for the image view) and with the cellforItemAtIndexPath set the images to the image view. (You can do this with custom cell. But for now, to get the collection view work, the assignment with tag for the imageview suits better)

UIImageView * ImageView = (UIImageView *)[cell viewWithTag:100];
ImageView.image = [UIImage imageNamed:[images objectAtIndex:indexPath.row]];

it happened to me that both the collectionView and the collection view cell had transparent backgrounds

In Swift,

self.label.textColor = UIColor.whiteColor()
Mr.Javed Multani
[self.collectionView registerNib:[UINib nibWithNibName:@"ProductCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ProductCollectionViewCell"];

self.collectionView.backgroundColor = [UIColor clearColor];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!