title: Maintain Scroll Position When Changing View Controller
body: <p>I have a recipe app with custom table views. The problem is, when entering a recipe view controller and returning to the recipe list view controller, it's not maintaining the previous scroll position. It's always back at the top. </p>
  
  <p>I'm wondering if it's something in my code or if it's something I need to add to maintain the previous position. </p>
  
  <p>This is the entire code from my recipe list view controller:</p>
  
  <pre><code>var recipeImgs: [UIImage] = [UIImage(named: "bananaPancakesCat.jpg")!,UIImage(named: "blackEyedPeaPattiesCat.jpg")!,UIImage(named: "blueberryMuffinsCat.jpg")!, UIImage(named: "buckwheatWafflesCat.jpg")!, UIImage(named: "cashewCreamCheeseCat.jpg")!, UIImage(named: "frenchToastCat.jpg")!, UIImage(named: "fruitSyrupCat.jpg")!, UIImage(named: "hashBrownsCat.jpg")!, UIImage(named: "proteinBarsCat.jpg")!, UIImage(named: "smoothieCat.jpg")!, UIImage(named: "tempehBaconCat.jpg")!, UIImage(named: "tofuQuicheCat.jpg")!]
  
  override func viewDidLoad() {
      super.viewDidLoad()
      tableView.delegate = self
      tableView.dataSource = self
  }
  
  override func viewDidDisappear(_ animated: Bool) {
      self.tableView.removeFromSuperview()
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      if let cell = tableView.dequeueReusableCell(withIdentifier: "RecipesTableViewCell") as? RecipesTableViewCell {
          cell.configureCell(recipeImgs[(indexPath as NSIndexPath).row])
          return cell
  
      } else {
          return RecipesTableViewCell()
      }
  
  }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      if (UIDevice.current.userInterfaceIdiom == .pad) {
          return 120
      }
          return 90.0
  }
  
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return recipeImgs.count
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      if (indexPath as NSIndexPath).row == 0 {
          performSegue(withIdentifier: "BRVC1", sender: self)
      } else if (indexPath as NSIndexPath).row == 1 {
          performSegue(withIdentifier: "BRVC2", sender: self)
      } else if (indexPath as NSIndexPath).row == 2 {
          performSegue(withIdentifier: "BRVC3", sender: self)
      } else if (indexPath as NSIndexPath).row == 3 {
          performSegue(withIdentifier: "BRVC4", sender: self)
      } else if (indexPath as NSIndexPath).row == 4 {
          performSegue(withIdentifier: "BRVC5", sender: self)
      } else if (indexPath as NSIndexPath).row == 5 {
          performSegue(withIdentifier: "BRVC6", sender: self)
      } else if (indexPath as NSIndexPath).row == 6 {
          performSegue(withIdentifier: "BRVC7", sender: self)
      } else if (indexPath as NSIndexPath).row == 7 {
          performSegue(withIdentifier: "BRVC8", sender: self)
      } else if (indexPath as NSIndexPath).row == 8 {
          performSegue(withIdentifier: "BRVC9", sender: self)
      } else if (indexPath as NSIndexPath).row == 9 {
          performSegue(withIdentifier: "BRVC10", sender: self)
      } else if (indexPath as NSIndexPath).row == 10 {
          performSegue(withIdentifier: "BRVC11", sender: self)
      } else {
          performSegue(withIdentifier: "BRVC12", sender: self)
      }
  }
  </code></pre>
  
  <p>And a video to demonstrate what's happening: <a href="https://www.dropbox.com/s/g6jy37t97d1ihft/ScreenRecording_09-19-2017%2015%3A31.mp4?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/g6jy37t97d1ihft/ScreenRecording_09-19-2017%2015%3A31.mp4?dl=0</a></p>