3

Xcode Version : 10.3

I used xib to create a UIView and added a UICollectionView to the UIView.

When I added UICollectionViewCell, it didn't work. Means I can't drag UICollectionViewCell into UICollectionView

The structure I want is like this

UIView(xib) -> UICollectionView(xib) -> UICollectionViewCell(xib)

Of course, I can add UICollectionViewCell with code, but why doesn't it work with xib? Does anyone know the reason?

enter image description here

enter image description here

Thanks

Nullable
  • 761
  • 5
  • 17

2 Answers2

0

You have to add prototype cells in UICollectionView in xib and then change it's class from UICollectionViewCell to your desired custom class.

Noor
  • 967
  • 7
  • 18
  • yes, add prototype cells not work with xib,I mean I can't drag `UICollectionViewCell` into `UICollectionView` – Nullable Sep 18 '19 at 09:22
  • It works. In your xib. select your collectionView and then increase the items count from 0 to 1 and change your prototype cell class. – Noor Sep 18 '19 at 09:33
0

@Nullable for your reference please check this gif demo gif to add custom cell in collection view inside xib

Noor
  • 967
  • 7
  • 18
  • Thank you, you are really attentive. My creation steps are like this: `cmd + n` -> `User interface` Select `View` -> Drag and drop `UICollectionView` -> Drag and drop `UICollectionViewCell ` failed. There is no `items` you mentioned, but it is working in `Storyboard` – Nullable Sep 18 '19 at 09:49
  • 1
    It is not possible for `View` xibs. Like in the gif above, I've added this in `UICollectionView` inside `CollectionCell` xib and then it's `items` property was available for prototyping cells. – Noor Sep 18 '19 at 10:42