UICollectionView doesn't contain UICollectionViewCell in IB

前端 未结 4 618
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 19:01

I\'m trying to add a UICollectionView to a .nib file in IB. I\'ve worked through a few tutorials and had no problems.

In my existing app, when I drag a collection vi

4条回答
  •  遥遥无期
    2020-12-18 19:14

    It's been a while since the question has been asked but I faced the same issue lately.

    Eventually, I found the answer here.

    In short:

    • You cannot drag and drop a UICollectionViewCell into a UICollectionView if you are in a .xib file. This is only possible in a storyboard.

    • The workaround is to create a .xib file for your custom cell and to register the cell manually using:

      [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:CELL_ID];

提交回复
热议问题