title: UiTableView number of generated cells
body: <p>I have two viewControllers. The first with a stepper:</p>
  
  <pre><code>var steppers : UIStepper?
  
  @IBOutlet weak var hourLabel: UILabel!
  @IBOutlet weak var stepper: UIStepper!
  
  @IBAction func stepper(_ sender: UIStepper) {
       hourLabel.text = String(sender.value)
  }
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if let np = segue.destination as? CourseClass2 {
          np.numberPlaces = Int(stepper.value)
      }
  }
  </code></pre>
  
  <p>and the second with a tableView:</p>
  
  <pre><code>private let resueIdentifier = "MyTableViewCell"
  
  extension UIViewController {
      func present(viewController : UIViewController, completion : (() -&gt; ())? = nil ){
          if let presented = self.presentedViewController {
              presented.dismiss(animated: true, completion: {
                  self.present(viewController, animated: true, completion: completion)
              })
          } else {
              self.present(viewController, animated: true, completion: completion)
          }
      }
  }
  
  class CourseClass2: UIViewController, UITableViewDelegate, UITableViewDataSource {
      @IBOutlet weak var tableView: UITableView!
  
      var locationManager:CLLocationManager?
      let minimumSpacing : CGFloat = 15 //CGFloat(MAXFLOAT)
      let cellWidth: CGFloat = 250
      let radius = 5000 // 5km
      var category : QCategoryy?
      var currentLocation : CLLocationCoordinate2D?
      var places: [QPlace] = []
      var isLoading = false
      var response : QNearbyPlacesResponse?
      var rows = 0
      var numberPlaces = 0
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.title = category?.name
          tableView.dataSource = self
          tableView.delegate = self
      }
  
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
  
          determineMyCurrentLocation()
      }
  
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
      }
  
      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
  
          rows = 0
       /*   insertRowsMode3()
          tableView.reloadData()  */
          category?.markView()
      }
  
      @IBAction func refreshTapped(_ sender: Any) {
          rows = 0
      /*    insertRowsMode3()  */
          tableView.reloadData()
      }
  
      func canLoadMore() -&gt; Bool {
          if isLoading {
              return false
          }
  
          if let response = self.response {
              if (!response.canLoadMore()) {
                  return false
              }
          }
  
          return true
      }
  
      func loadPlaces(_ force:Bool) {
          if !force {
              if !canLoadMore() {
                  return
              }
          }
  
          print("load more")
          isLoading = true
          NearbyPlaces.getNearbyPlaces(by: category?.name ?? "food", coordinates: currentLocation!, radius: radius, token: self.response?.nextPageToken, completion: didReceiveResponse)
      }
  
      func didReceiveResponse(response:QNearbyPlacesResponse?, error : Error?) -&gt; Void {
          if let error = error {
              let alertController = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
              let actionDismiss = UIAlertAction(title: "Dismiss", style: .cancel, handler: nil)
              let actionRetry = UIAlertAction(title: "Retry", style: .default, handler: { (action) in
                  DispatchQueue.main.async {
                      self.loadPlaces(true)
                  }
              })
              alertController.addAction(actionRetry)
              alertController.addAction(actionDismiss)
              DispatchQueue.main.async {
                  self.present(viewController: alertController)
  
              }
          }
          if let response = response {
              self.response = response
              if response.status == "OK" {
                  if let placesDownloaded = response.places {
                      places.append(contentsOf: placesDownloaded)
                  }
  
                 self.tableView?.reloadData()
              } else {
                  let alert = UIAlertController.init(title: "Error", message: response.status, preferredStyle: .alert)
                  alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
                  alert.addAction(UIAlertAction.init(title: "Retry", style: .default, handler: { (action) in
                      DispatchQueue.main.async {
                          self.loadPlaces(true)
                      }
                  }))
                   self.present(viewController: alert)
              }
              isLoading = false
          }
          else {
              print("response is nil")
          }
      }
  
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          print("numberOfsection Call")
          return 1
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          print("numberOfRows Call")
          return  places.count   /*  rows   */
      }
  
      public  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: resueIdentifier, for: indexPath) as! MyTableViewCell
  
          let place = places[indexPath.row]
          cell.update(place: place)
  
          if indexPath.row == places.count - 1 {
              loadPlaces(false)
          }
          print("CellForRow Call")
          return (cell)
      }
  
      func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          tableView.deselectRow(at: indexPath, animated: true)
  
          UIView.animate(withDuration: 0.2, animations: {
          let cell = tableView.dequeueReusableCell(withIdentifier: "MyTableViewCell", for: indexPath) as! MyTableViewCell
      })
  
          performSegue(withIdentifier: "goToLast" , sender: indexPath.row)
      }
  
      func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
          return 100
      }
  
      func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -&gt; Bool {
          return true
      }
  
      func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
          if editingStyle == UITableViewCellEditingStyle.delete {
              places.remove(at: indexPath.row)
              tableView.deleteRows(at: [indexPath], with: .fade)
          }
      }
  
      func didReceiveUserLocation(_ userLocation:CLLocation) {
          currentLocation = userLocation.coordinate
  
          loadPlaces(true)
      }
  </code></pre>
  
  <p>I added only the code useful for the question. As you can see I'm trying to pass from the first VC to the second this value:</p>
  
  <pre><code>override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if let np = segue.destination as? CourseClass2 {
          np.numberPlaces = Int(stepper.value)
      }
  }
  </code></pre>
  
  <p>Because I would like to add a limit to the number of cells that spawn when loading the tableview in the second viewController (and I want this limit to be chosen by the user with the stepper in the previous controller), how do I have to modify the tableView to make sure that the number of cells generated is equal to the value of <code>var numberPlaces</code>?  </p>