UICollectionView cellForItemAtIndexPath not registering cell

后端 未结 5 1622
甜味超标
甜味超标 2021-02-06 23:15

I am trying to use UICollectionViewCell, since all I want to display is an image. I can add the image to the cell using UIColor colorWithImage: on the

5条回答
  •  耶瑟儿~
    2021-02-07 00:13

    If you are using xib in applivation then add following in your viewdidLoad method

        [self.myCollectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CellIdentifier"];
    

    otherwise If you using storyboard add following

      [self.myCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"CellIdentifier"];
    

    Finally add this (If not)

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CellIdentifier" forIndexPath:indexPath];
     return cell;
    }
    

    Hope above will help.

提交回复
热议问题