title: How to use UITableViews to create static and dynamic rows with Swift
body: <p>This question follows up from this: <a href="https://stackoverflow.com/questions/44332184/use-uicollectionviews-to-create-dynamic-and-multiple-features">Use UICollectionViews to create dynamic and multiple features</a>.</p>
  
  <p>I am able to create a static cell which displays the name and image of the recipe similar like this app:</p>
  
  <p><a href="https://i.stack.imgur.com/L8MMC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L8MMC.jpg" alt="enter image description here"></a></p>
  
  <p>Where I am stuck is creating a dynamic row which changes based on the amount of data inside i.e. utensils or nutritional values like the image below:</p>
  
  <p><a href="https://i.stack.imgur.com/IjHeE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IjHeE.jpg" alt="enter image description here"></a></p>
  
  <p>I know how to display rows of data on tableView normally. But not sure how to embed it into a section inside a tableView. I attempted to add multiple prototype cells and assign them to a subclass of <code>UITableViewCell</code>'s. Then I try to use <code>if</code> statements in my <code>cellForRow</code> but this isn't soling my issue.</p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      if indexPath.row == 0 {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! FirstCell
          //set the data here
  
          cell.recipeTitle.text = recipe.name
          cell.imageView.image = UIImage(named: "url")
          return cell
      }
      else if indexPath.row == 1 {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! SecondCell
          //set the data here
          return cell
      }
      else {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell3", for: indexPath) as! ThirdCell
          //set the data here
          return cell
      }
  }
  </code></pre>
  
  <p>I have also looked at this demonstration: <a href="https://medium.com/ios-os-x-development/ios-how-to-build-a-table-view-with-multiple-cell-types-2df91a206429" rel="nofollow noreferrer">https://medium.com/ios-os-x-development/ios-how-to-build-a-table-view-with-multiple-cell-types-2df91a206429</a>, which is near to what I want to achieve but I have found it quite difficult to adapt to it.</p>
  
  <p>If someone could direct me on how best to approach this or a good example then I would really appreciate it.</p>