title: How to create dynamic tableview with multiple row in swift?
body: <p>I want to create dynamically table view with multiple rows which contains different data. I don't know how to create new row in swift. I want to create 3 rows and add different data to each row. I Know i can update array data and reload tableview.But when i updated data  in loop and reloaded tableview then only last data is displaying. Tableview missing data which is added in for loop at index 2. 
  This is my code :</p>
  
  <p>var i = 0</p>
  
  <pre><code>  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      tableView.frame = CGRect(x: 5, y:200 ,width: self.view.frame.width, height: 400)
      tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
      tableView.delegate = self
      tableView.dataSource = self
      tableView.layer.borderWidth = 2
  
      self.view.addSubview(tableView)
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return products.count
  }
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 1
  }
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
  
  
      let tf = UITextField(frame: CGRect(x: 320, y: 10*i , width: 300, height:20))
      tf.placeholder = "_"
      tf.tag = indexPath.row
      tf.font = UIFont.systemFont(ofSize: 15)
  
      let pest = UILabel(frame: CGRect(x: 10, y: 10*i, width: 300, height: 60))
  
       pest.font = UIFont.systemFont(ofSize: 15)
       pest.numberOfLines = 0
       pest.text = self.products[indexPath.row]
  
      let pp = UILabel()
      pp.text = "PP"
  
  
      cell.contentView.addSubview(pest)
      cell.contentView.addSubview(tf)
  
  
  
     return cell
  
  }
  override func viewDidAppear(_ animated: Bool) {
  
  
      createTable()
  }
  
    func createTable(){
      for index in 1...3{
          if(index == 2){
               i = index
               self.products = ["r1","r2","r3","r4"]
               tableView.reloadData()
  
  
          }
        else  if(index == 3){
  
              i = index
              self.products = ["d1","d2","d3","d4"]
              tableView.reloadData()
  
          }
          else{
  
          }
  
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HxfH9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HxfH9.jpg" alt="enter image description here"></a></p>