title: UITableView ordering nib rows
body: <p>I have the following TableViewController code for creating a table with rows:</p>
  
  <pre><code>override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      switch (arrayData[indexPath.row].cell) {
      case 0:
  
          let cell = Bundle.main.loadNibNamed("FirstCell", owner: self, options: nil)?.first as! FirstCell
          if arrayData[indexPath.row].image == nil {
              cell.firstImage.image = arrayData[indexPath.row].image
          } else {
              cell.firstImage.image = #imageLiteral(resourceName: "pump")
          }
          cell.firstCellLabel.text = arrayData[indexPath.row].text
          cell.backgroundColor = UIColor.clear
  
          return cell
  
      case 1...98:
          let cell = Bundle.main.loadNibNamed("StationPumpCell", owner: self, options: nil)?.first as! StationPumpCell
          //cell.pumpImage.image = arrayData[indexPath.row].image
          cell.pumpLabel.text = arrayData[indexPath.row].text
          cell.backgroundColor = UIColor.clear
  
          switch (arrayData[indexPath.row].stat) {
              case 1:
                  cell.pumpImage.image = #imageLiteral(resourceName: "online")
              case 3:
                  cell.pumpImage.image = #imageLiteral(resourceName: "warning")
                  cell.pumpLabel.textColor = UIColor.orange
              default:
                  cell.pumpImage.image = #imageLiteral(resourceName: "offline")
                  cell.pumpLabel.textColor = UIColor.lightGray
          }
  
          if (arrayData[indexPath.row].map == 0) {
              cell.pumpLabel.text?.append(" - test")
          }
  
          return cell
  
      case 99:
          let cell = Bundle.main.loadNibNamed("LastCell", owner: self, options: nil)?.first as! LastCell
          return cell
  
      default:
          let cell = Bundle.main.loadNibNamed("FirstCell", owner: self, options: nil)?.first as! FirstCell
          //cell.firstImage.image = arrayData[indexPath.row].image
          //cell.firstCellLabel.text = arrayData[indexPath.row].text
  
          print("oops")
  
          return cell
      }
  
  }
  </code></pre>
  
  <p>the array looks like this</p>
  
  <pre><code>cellData(cell : 0, text : self.annotationTitle, image: self.stationImage, stat: nil, map: nil)
  </code></pre>
  
  <p>The above '0' is the header and should always be first.
  Following cells are numbered 1...98 and the footer is 99. Ie. the order is: header, rows of data, footer.</p>
  
  <p>The problem is that sometimes the footer is at the very top, ie. ordered footer, header, data. Other times its footer, data, header. I have not yet been able to get the correct the order.</p>
  
  <p>I don't know if this has anything to do with the data being collected from an online json file and some cells loading slightly later than the footer, which has no content inside.</p>
  
  <p>The image for the header (cell 0) is found like this:</p>
  
  <pre><code>   Alamofire.request(stationsURL).responseJSON { response in
  
          if response.result.value != nil {
              NSLog("Success")
              let stationsJSON = JSON(response.result.value!)
  
              let stationResp = stationsJSON["Stations"][0]["photos"][0].stringValue
  
              stationPhoto = stationResp
  
              print(stationPhoto)
  
              let imageURL = "http://www.123.com/files/thumb100_" + stationPhoto
  
              print(imageURL)
  
              Alamofire.request(imageURL).responseImage { response in
  
                  if response.result.value != nil {
  
                      self.stationImage = response.result.value!
  
                      debugPrint("Stationimage: ")
                      debugPrint(self.stationImage)
  
                  }
              }
  
          }
          DispatchQueue.main.async {
              self.tableView.reloadData()
          }
      }
  </code></pre>
  
  <p>That debug print of Stationimage is the very last thing that loads, according to the debug window and the header cell shows no image: <code>"Stationimage: " &lt;UIImage: 0x17028ffa0&gt;, {50, 37.5}</code> and I think this may be what's causing the bad ordering.</p>
  
  <pre><code>2017-03-10 04:34:00.290406 Testfile[14214:6238055] [INFO] {}[Database]: recovered 12 frames from WAL file …Testfile/Cache.db-wal (Code 283)
  2017-03-10 04:34:00.678731 Testfile[14214:6237998] Success
  Demo
  http://**json address**
  2017-03-10 04:34:07.753937 Testfile[14214:6237998] Success
  p9_2.jpg
  http://**json address**/thumb100_p9_2.jpg
  [Testfile.cellData(cell: 99, text: nil, image: nil, stat: nil, map: nil), 
  Testfile.cellData(cell: 0, text: Demo, image: Optional(&lt;UIImage: 0x17409d1a0&gt;, {0, 0}), stat: nil, map: nil)]
  2017-03-10 04:34:07.872660 Testfile[14214:6237998] Success
  5
  [Testfile.cellData(cell: 99, text: nil, image: nil, stat: nil, map: nil), 
  Testfile.cellData(cell: 0, text: Demo, image: Optional(&lt;UIImage: 0x17409d1a0&gt;, {0, 0}), stat: nil, map: nil), 
  Testfile.cellData(cell: 1, text: Name 1, image: nil, stat: 1, map: 1), 
  Testfile.cellData(cell: 2, text: Name 2, image: nil, stat: 1, map: 1), 
  Testfile.cellData(cell: 3, text: Name 3, image: nil, stat: 1, map: 1), 
  Testfile.cellData(cell: 4, text: Name 4, image: nil, stat: 0, map: 1), 
  Testfile.cellData(cell: 5, text: Name 5, image: nil, stat: 0, map: 1)]
  "Stationimage: "
  &lt;UIImage: 0x17409f8b0&gt;, {50, 37.5}
  </code></pre>
  
  <p>What is the correct way to order the cells so that 0 is always first, 99 always last?</p>