title: Reload collectionview with two types custom cells using segmented control
body: <p>I'm trying to achieve the following behaviour with 2 types of custom collection-view cells, lets call it A and B:</p>
  
  <p>I have a segmented control with 2 options, images and music. When I click on the images option, the collection-view will show me the images by using custom cell A, when I click on music, it will reload the table and will show me the music by using custom cell B. This happens by using the same collection-view.</p>
  
  <p>My problem is that I get the following error:</p>
  
  <blockquote>
    <p>could not dequeue a view of kind: UICollectionElementKindCell with
    identifier PictureCell - must register a nib or a class for the
    identifier or connect a prototype cell in a storyboard'</p>
  </blockquote>
  
  <p>My current code:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          switch mySegmentedControl.selectedSegmentIndex
          {
          case 0:
              let nibPicture = UINib(nibName: "PictureCell", bundle: nil)
              myCollectionView.register(nibPicture, forCellWithReuseIdentifier: "Cell")
              let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for:indexPath) as! PictureCollectionViewCell
              let fruits: [MyItem] = dataSource.itemsInGroup(indexPath.section)
              let fruit = fruits[indexPath.row]
  
              let name = fruit.name!
              cell.fileImage.image = UIImage(named: name.lowercased())
  
              return cell
          case 1:
              let nibMusic = UINib(nibName: "MusicCell", bundle: nil)
              myCollectionView.register(nibMusic, forCellWithReuseIdentifier: "Cell")
              let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for:indexPath) as! MusicCollectionViewCell
              let fruits: [MyItem] = dataSource.itemsInGroup(indexPath.section)
              let fruit = fruits[indexPath.row]
  
              let name = fruit.name!
              cell.labelAuthor.text = name
              cell.labelMediaName.text = name
              return cell
          default:
              let nibPicture = UINib(nibName: "PictureCell", bundle: nil)
              myCollectionView.register(nibPicture, forCellWithReuseIdentifier: "Cell")
              let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for:indexPath) as! PictureCollectionViewCell
              let fruits: [MyItem] = dataSource.itemsInGroup(indexPath.section)
              let fruit = fruits[indexPath.row]
  
              let name = fruit.name!
              cell.fileImage.image = UIImage(named: name.lowercased())
  
              return cell
          }
      }
  </code></pre>
  
  <p>The initial load of the images works fine but when I change to music It crashes.
  Here is a demo showing the problem: <a href="https://www.dropbox.com/s/i48sa42hsa2iyi3/collectionTest.zip?dl=0" rel="nofollow noreferrer">Demo Link</a></p>