SteBra
SteBra

Reputation: 4247

How to wire up UICollectionView in a custom UIView - Swift

I'm dealing with a strange issue where I cannot wire up UICollectionView when I want to set it up in a custom UIView.

The reason for having it in UIView instead of UIViewController is that I am creating several custom Views and I'm showing only one per time.

Now, the issue I have is that I am able to drag UICollectionView inside my custom UIView nib but I cannot drop any UICollectionViewCell on it. However, when I do the same thing inside a UIView of a UIVIewController, not only that I am able to drop a cell on it - the cell appears by default.

This is what appears when i place collection view inside a view controller: enter image description here

This is when I add it to a custom UIView enter image description here

SO my question is, how to add a cell inside a view?

Upvotes: 1

Views: 1654

Answers (1)

Vlad
Vlad

Reputation: 7260

You can't do this in view's xib file. Create a separate xib file for your cell and register it in collection view:

let cellNib = UINib(nibName: "YourCellNibFileName", bundle: nil)
collectionView.registerNib(cellNib, forCellWithReuseIdentifier: "YourCellIdentifier")

Upvotes: 2

Related Questions