title: how to execute collectionView class from different ViewController
body: <p>i have a <strong>collectionView</strong> class</p>
  
  <pre><code>class LC: UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
  
  //in LC
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if let VC = segue.destination as? VC2 {
          VC.Rpe = Pass
      }
  }
  </code></pre>
  
  <p><strong>it's working fine</strong> , in <strong>VC2</strong> i have a function when executed it should segue to the next cell in the <code>collection view</code></p>
  
  <p>i'm not sure how or what is the best way to do it (<code>reload</code> <strong>VC2</strong> with the next <code>collection view cell</code> details?, or run the <code>collection view</code> functions programmatically )</p>
  
  <p><strong>update</strong></p>
  
  <pre><code>import Foundation
  import UIKit
  
  class View2: UIViewController {
  
  @IBOutlet var Q_Pic: UIImageView!
  @IBOutlet var Q_que: UILabel!
  var SelectedCell: Ques!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      Q_Pic.image = UIImage(named: SelectedCell.LIMG)
      Q_que.text = SelectedCell.Q
  }
  
  @IBAction func herewego(_ sender: Any) {
      print("when the user press this button it should take him directly to the next cell detail , i don't want the user to go back to collection view and choose the next cell")
  }
  }
  </code></pre>
  
  <p><strong>data</strong></p>
  
  <pre><code>let Q_A_TEST_MOH = [
  Ques(Q: "Q1? ",LIMG: "1"),
  Ques(Q: "Q2? ",LIMG: "2"),
  Ques(Q: "Q3?",LIMG: "3"),
  Ques(Q: "Q4?",LIMG: "4"),
  Ques(Q: "Q5?",LIMG: "5")
  ]
  
  struct Ques {
  var Q : String
  var LIMG: String
  }
  </code></pre>
  
  <p><strong>UICollectionViewController</strong></p>
  
  <pre><code>import Foundation
  import UIKit
  
  class test:UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
  
  @IBOutlet var CollectionView: UICollectionView!
  var Levelssss: [Ques]!
  var ToPass: Ques!
  var SelectedCategory: String!
  var Level: Int!
  override func viewDidLoad() {
      super.viewDidLoad()
      CollectionView.delegate = self
      CollectionView.dataSource = self
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return Q_A_TEST_MOH.count
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "LevelCell2", for: indexPath) as? cell1 {
          let r = Q_A_TEST_MOH[indexPath.item]
          cell.congigureCell(EditLater: r)
          return cell
      }
      return UICollectionViewCell()
  }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      ToPass = Q_A_TEST_MOH[indexPath.item]
      performSegue(withIdentifier: "To", sender: self)
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if let detalsVC = segue.destination as? View2 {
          detalsVC.SelectedCell = ToPass
      }
  }
  }
  </code></pre>
  
  <p><strong>UICollectionViewCell</strong></p>
  
  <pre><code>import UIKit
  
  class cell1: UICollectionViewCell {
  
  @IBOutlet var BB: UIButton!
  
  override func awakeFromNib() {
      super.awakeFromNib()
      BB.layer.cornerRadius = 10
  }
  
  func congigureCell(EditLater: Ques){
      BB.setImage(UIImage(named: EditLater.LIMG), for: .normal)
  }
  }
  </code></pre>
  
  <p>Download project from here : <a href="http://s000.tinyupload.com/index.php?file_id=05310788991055115831" rel="nofollow noreferrer">download the project</a></p>