title: Creating sections with headers with two dynamic tableviewcells in Swift
body: <p>I have a table view with two cells, "electionInfo" and "candidates". Candidates returns an array of the candidates, while electionInfo gives a single text body (so just one cell). I'd like to divide them into two sections with their respective headers. Right now, it gives me one header for both cells. How do I fix it?</p>
  
  <p>Thanks!! </p>
  
  <p>My code... </p>
  
  <pre><code>@IBOutlet weak var table: UITableView!
  
      var info: [PFObject] = []
      var items: [PFObject] = []
      let titles = ["Election Info", "Candidates"]
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return self.items.count + 1
      }
  
      func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
  
          return self.items.count   
      }
  
      func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -&gt; String? {
          return titles[section]
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          if indexPath.row == self.items.count {
  
              let cell = table.dequeueReusableCellWithIdentifier("candidateCell") as! CandidateTableViewCell
              let candidate = items[indexPath.row]
              cell.candidateImage.file = candidate["image"] as! PFFile
              cell.candidateImage.loadInBackground()
              cell.candidateName?.text = candidate["name"] as! String
              cell.candidateParty?.text = candidate["partyAffiliation"] as! String
  
              return cell
  
      } else {
  
              let cell = table.dequeueReusableCellWithIdentifier("electionCell") as! ElectionInfoTableViewCell
              cell.electionInfo.text = "hey there"
  
          }
        }
      }
  </code></pre>