title: loading a UITableViewController from a selected indexpath in a UICollectionViewController
body: <p>Im trying to get the <code>VC</code> that corresponds with the cell of the table view to load when tapped. I am trying to set the <code>indexPath</code> as the <code>selectedIndexPath</code> and set up the segue in the collection view, then use that in the tableView but it is throwing an error. Here is the code. </p>
  
  <pre><code>import UIKit
  
  private let reuseIdentifier = "profileCell"
  
  
  class CompanyCollectionViewController: UICollectionViewController {
  
  //MARK: - View Did Load
  
  override func viewDidLoad() {
      super.viewDidLoad()
      navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
  
  }
  
  
  // MARK: UICollectionViewDataSource
  
  override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  
  override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return stuff.company.count
  }
  
  override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ProfileCollectionViewCell
  
      cell.profileImageView.image = UIImage(named: stuff.company[indexPath.row]["image"]!)
  
      return cell
  }
  
  //MARK: - Prepare For Segue
  
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if segue.identifier == "profileSegue" {
          let profileVC = segue.destinationViewController as!
              MyProfileTableViewController
          let cell = sender as! UICollectionViewCell
          let indexPath = collectionView?.indexPathForCell(cell)
  
          profileVC.selectedIndexPath = indexPath
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and then </p>
  
  <pre><code>import UIKit
  
  class MyProfileTableViewController: UITableViewController {
  
  //MARK: - View Did Load
  
  override func viewDidLoad() {
      super.viewDidLoad()
  }
  
  
  
  
  
  //MARK: - Table View Data Source
  
  override func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  
  override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return 1
  }
  
  override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
      if let indexPath = selectedIndexPath {
  
          let row = stuff.company[indexPath.row]
  
          let cell = tableView.dequeueReusableCellWithIdentifier("myProfileCell", forIndexPath: indexPath) as! MyProfileTableViewCell
              cell.heroImageView.image = UIImage(named: row["image"]!)
              title = row["name"]
              cell.nameLabel.text = row["name"]
              cell.statusLabel.text = row["description"]
              return cell
  
      } else {
          let cell = tableView.dequeueReusableCellWithIdentifier("myProfileCell", forIndexPath: indexPath) as! MyProfileTableViewCell
          cell.heroImageView.image = UIImage(named: stuff.profile["profile image"]!)
          title = stuff.profile["name"]
          cell.nameLabel.text = stuff.profile["name"]
          cell.statusLabel.text = stuff.profile["status"]
          return cell
      }
  }
  
  //MARK: - Variables
  
  var selectedIndexPath: NSIndexPath?
  </code></pre>
  
  <p>}</p>