title: UITableView section with cells
body: <p>I am trying to make something like <a href="https://i.stack.imgur.com/vLHRS.png" rel="nofollow noreferrer">this</a> but I am having trouble adding the date to my tableview. I have a Realm database with dates(Date), names(String) and numbers(Int).</p>
  
  <p>I have successfully added the date to each section, but I am having trouble finding out how to add the names and numbers to the cells. There are multiple rows with the same date, but with different names and numbers.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>import UIKit
  import RealmSwift
  
  class myViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
      @IBOutlet weak var tableView: UITableView!
  
      var data:Results&lt;Objects&gt;!
      var result:[Objects] = []
  
      let cellSpacingHeight: CGFloat = 5
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          tableView.delegate = self
          tableView.dataSource = self
  
          retreiveData()
      }
  
      func retreiveData() {
          let realm = try! Realm()
  
          // Retreive data
          self.data = realm.objects(Objects.self).sorted(byKeyPath: "date",ascending: false)
          self.result = Array(self.data)
  
          print(result)
  
          tableView.reloadData()
      }
  
      // MARK: - Table View delegate methods
  
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          return self.result.count
      }
  
      // Set the spacing between sections
      func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
          return cellSpacingHeight
      }
  
      /*func numberOfSections(in tableView: UITableView) -&gt; Int {
          return 1
      }*/
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return result.count
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
  
  
          let dateFormatter = DateFormatter()
          dateFormatter.dateFormat = "EEEE - dd.MM.yyyy"
  
          let stringGivenDate = dateFormatter.string(from: result[indexPath.section].date!)
  
          cell.textLabel?.text = "\(stringGivenDate)"
          cell.detailTextLabel?.text = "\(result[indexPath.section].name!)"
  
          return cell
      }
  }
  </code></pre>