title: UICollectionView into UIView in Swift
body: <p>I have a problem when I try to use a CollectionView into UIView. </p>
  
  <p>This is the code example of my view. </p>
  
  <pre><code>class CampanasView: UIView, UICollectionViewDelegate, UICollectionViewDataSource {
  
  @IBOutlet weak var collectionView: UICollectionView!
  
  class func create() -&gt; CampanasView {
      let nib = UINib(nibName: "CampanasView", bundle: nil)
      let view = nib.instantiate(withOwner: self, options: nil)[0] as? CampanasView
  
      //if you use xibs:
      view?.collectionView.register(UINib(nibName: "CampanaCell", bundle: nil), forCellWithReuseIdentifier: "CampanaCell")
      view?.collectionView.reloadData()
      return view!
  }
  
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return 20
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CampanaCell", for: indexPath) as! CampanaCell
  
  
      return cell
  }
  
  }
  </code></pre>
  
  <p>This is the xib</p>
  
  <p><a href="https://i.stack.imgur.com/Oq5IZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oq5IZ.png" alt="Xib File of the UIView"></a></p>
  
  <p>In my ViewController I have this code to add UIView into ViewController</p>
  
  <pre><code>var campanasView: CampanasView?
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
  
      self.campanasView = CampanasView.create()
      _ = JAutolayouts.fillContainer(self.contentView, view: self.campanasView!)
  }
  </code></pre>
  
  <p>This is the error. </p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[WinUp.CampanasView collectionView:numberOfItemsInSection:]: unrecognized selector sent to class 0x10beac100'</p>
  </blockquote>