Console error: UICollectionView must be initialized with a non-nil layout parameter

后端 未结 2 1698
忘了有多久
忘了有多久 2020-12-21 08:26

I\'m new to UICollectionView and I\'m following a tutorial that I found on Youtube, but i\'m stuck on an error I can\'t figure out.

When I run the app w

相关标签:
2条回答
  • 2020-12-21 09:24

    it is an error while registering the uicollectionviewcell view class. To resolve put the below line in your code:

    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];
    
    0 讨论(0)
  • 2020-12-21 09:25

    Register Collection cell in viewDidLoad method ::

    [self.collView registerClass:[mineCell class] forCellWithReuseIdentifier:@"cvCell"];
    

    Try this after above line:

    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    [flow setItemSize:CGSizeMake(60, 60)];
    [flow setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    [self.collView setCollectionViewLayout:flow];
    

    Here, mineCell is my custom collectionViewCell or you can use [UICollectionViewCell class]directly.

    Thanks.

    0 讨论(0)
提交回复
热议问题