//
//  SurveyTableViewDelegate.swift
//  Pods
//
//  Created by Nora Mullaney on 3/15/17.
//
//

import Foundation

open class SurveyTableViewDelegate : NSObject, UITableViewDelegate {
   
   var surveyQuestions : SurveyQuestions
   var heightAtIndexPath = NSMutableDictionary()
   
   public init(_ surveyQuestions : SurveyQuestions) {
      self.surveyQuestions = surveyQuestions
   }
   
   open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      TableUIUpdater.updateTable(self.surveyQuestions.selectedRowAt(indexPath), tableView: tableView)
      tableView.deselectRow(at: indexPath, animated: false)
   }
   
   open func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
      if let height = heightAtIndexPath.object(forKey: indexPath) as? NSNumber {
         return CGFloat(height.floatValue)
      } else {
         return UITableViewAutomaticDimension
      }
   }
   
   open func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
      let height = cell.frame.size.height
      self.heightAtIndexPath.setObject(height, forKey: indexPath as NSCopying)
   }
}

//
//  SurveyTableViewDelegate.swift
//  Pods
//
//  Created by Nora Mullaney on 3/15/17.
//
//

import Foundation

open class SurveyTableViewDelegate : NSObject, UITableViewDelegate {
   
   var surveyQuestions : SurveyQuestions
   
   public init(_ surveyQuestions : SurveyQuestions) {
      self.surveyQuestions = surveyQuestions
   }
   
   open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      TableUIUpdater.updateTable(self.surveyQuestions.selectedRowAt(indexPath), tableView: tableView)
      tableView.deselectRow(at: indexPath, animated: false)
   }
   
}

--- 
+++ 
@@ -11,6 +11,7 @@
 open class SurveyTableViewDelegate : NSObject, UITableViewDelegate {
    
    var surveyQuestions : SurveyQuestions
+   var heightAtIndexPath = NSMutableDictionary()
    
    public init(_ surveyQuestions : SurveyQuestions) {
       self.surveyQuestions = surveyQuestions
@@ -21,4 +22,16 @@
       tableView.deselectRow(at: indexPath, animated: false)
    }
    
+   open func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
+      if let height = heightAtIndexPath.object(forKey: indexPath) as? NSNumber {
+         return CGFloat(height.floatValue)
+      } else {
+         return UITableViewAutomaticDimension
+      }
+   }
+   
+   open func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
+      let height = cell.frame.size.height
+      self.heightAtIndexPath.setObject(height, forKey: indexPath as NSCopying)
+   }
 }
Fix jerkiness of scrolling by giving better estimates for height
