title: How to list all cells selected on a collection view's into another view
body: <p>I'm developing an scene using a Split View component. In my master view I have a table view inside a container, and in my detail view I have a collection view inside a container. </p>
  
  <p><a href="https://i.stack.imgur.com/YUS1Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YUS1Z.png" alt="Master View Containers"></a></p>
  
  <p><a href="https://i.stack.imgur.com/dnBDC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dnBDC.png" alt="Detail View containers"></a></p>
  
  <p>I'm trying get all cells selected on my 'detail view's collection view container' and list on my 'master view table view' but I don't know how to get access from this information. On the detail view I know that I can have the cells selected using "collectionView.indexPathsForSelectedItems()", but how can I access this information outside the view and create a new table cell on the master view table everytime a cell is selected on detail view collection view? </p>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>I'm reading about delegation and I wrote these code to try to share the data through view but it didn't work:</p>
  
  <p>1) I wrote this delegation protocol: </p>
  
  <pre><code>protocol MasterDetailShareDataDelegate: class {
    func reloadMasterViewWithSelectedCells(_ data: Set&lt;String&gt;)
  } 
  </code></pre>
  
  <p>2) I put the delegate var on the origin view:</p>
  
  <pre><code>class ProductsPlatesViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
    var platesSelected: Set&lt;String&gt; = Set()
    var delegate: MasterDetailShareDataDelegate?
  
    ...
  
    func passDataBackWards() {
      let data = platesSelected
      delegate?.reloadMasterViewWithSelectedCells(data)
    }
  
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      var cell = collectionView.cellForItem(at: indexPath) as! ProductsPlatesCollectionViewCell
      cell.backgroundColor = UIColor.green
  
      platesSelected = Set()
  
      for item in collectionView.indexPathsForSelectedItems!  {
        platesSelected.insert(self.plates[item.row])
      }
      passDataBackWards()
    }
  
    func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
      var cell = collectionView.cellForItem(at: indexPath) as! ProductsPlatesCollectionViewCell
      cell.backgroundColor = UIColor.clear
  
      platesSelected = Set()
  
      for item in collectionView.indexPathsForSelectedItems!  {
        platesSelected.insert(self.plates[item.row])
      }
      passDataBackWards()
    }
  }
  </code></pre>
  
  <p>3) Wrote this code on the Destiny View: </p>
  
  <pre><code>class NewBudgetViewController: UIViewController, MasterDetailShareDataDelegate {
  
    override func viewDidLoad() {
      super.viewDidLoad()
  
      let theProductsPlatesViewController = ProductsPlatesViewController()
      theProductsPlatesViewController.delegate = self
      ...
    }
  
  
    func reloadMasterViewWithSelectedCells(_ data: Set&lt;String&gt;) {
      print(data)
    }
  </code></pre>
  
  <p>The function reloadMasterViewWithSelectedCells in NewBudgetViewController is not being called. Can someone please tell me why? :(</p>