title: Passing data from tableViewCell to another VC
body: <p>I'm trying to pass the text of a tableViewCell into another VC and use that text to determine a displayed image , but regardless of what I do it only ever displays the text and image of the last cell. Here is my code, any help would be massively appreciated.</p>
  
  <p>import UIKit</p>
  
  <p>class TheExerciseLibrary: UIViewController, UITableViewDataSource, UITableViewDelegate {</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
  
      exerciseTableView.delegate = self
      exerciseTableView.dataSource = self
  }
  
  var exercises = ExerciseLibrary()
  var mainCell = UITableViewCell()
  
  @IBOutlet weak var exerciseTableView: UITableView!
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      return exercises.exerciseArray.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCell(withIdentifier: "prototypeCell2", for: indexPath)
  
      cell.textLabel?.text = exercises.exerciseArray[indexPath.row]
      cell.layer.borderWidth = 5
      cell.layer.cornerRadius = 20
      cell.layer.borderColor = #colorLiteral(red: 0, green: 0.3285208941, blue: 0.5748849511, alpha: 1)
      cell.textLabel?.textColor = UIColor.black
      cell.textLabel?.adjustsFontSizeToFitWidth = true
      cell.textLabel?.font = .boldSystemFont(ofSize: 15)
  
      return cell
  </code></pre>
  
  <p>}</p>
  
  <pre><code>override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  
      let displayVC = segue.destination as! Exercise
  
      if mainCell.textLabel?.text == "Bench press" {
          displayVC.navTitle = "Bench Press"
        displayVC.image = UIImage(named: "BenchPress")!
            }
  
      if mainCell.textLabel?.text == "Barbell squat" {
          displayVC.navTitle = "Barbell Squat"
        displayVC.image = UIImage(named: "BBSquat")!
        }
      if mainCell.textLabel?.text == "Shoulder press" {
          displayVC.navTitle = "Shoulder Press"
          displayVC.image = UIImage(named: "BBShoulderPress")!
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>On the next VC it always displays Shoulder press and the shoulder press image regardless of what cell is clicked.</p>
  
  <p>The segue is set up via the ctrl drag method in story board.</p>
  
  <p>Thank you.</p>
  
  <p>Josh</p>