title: how to organize tableview cells
body: <p>I have two different kinds of tableview cells in one table view. The first cell prints out original comments to a post, the second cell prints out comments to another comment. Currently, the tableview prints out all the correct cells in no particular order. However, I want to print the cells in a particular order. I want the cells that contain comments to another comment to appear below the comment it is being commented on. </p>
  
  <pre><code>  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          // Configure the cell...
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "Main", for: indexPath) as! PostTableViewCell
  
          //Configure the cell
  
          cell.PostView.layer.cornerRadius = 5
          cell.PostView.layer.masksToBounds = false
          cell.PostView.layer.shadowColor = UIColor.black.withAlphaComponent(0.4).cgColor
          cell.PostView.layer.shadowOffset = CGSize(width: 0, height: 0)
          cell.PostView.layer.shadowOpacity = 0.9
  
          let post = Comments[indexPath.row] as! [String: AnyObject]
          let commentname = post["author"] as? String
          sendAuthor = post["author"] as? String
          cell.CommentersName.setTitle(commentname, for: .normal)
  
          if let seconds = post["pub_time"] as? Double {
              let timeStampDate = NSDate(timeIntervalSince1970: seconds/1000)
              let dateFormatter = DateFormatter()
              dateFormatter.dateFormat = "MMM d, yyyy"
              let formating = timeStampDate as Date
  
  
              cell.CommentTime.text = dateFormatter.string(from: formating)
  
  
          }
  
          cell.comment.text = post["content"] as? String
  
  
           textViewDidChange(cell.comment)
  
          cell.comment.frame.size.width = 344
          cell.comment.sizeToFit()
          cell.comment.clipsToBounds = true
  
          cell.REply.frame.origin.y = cell.comment.frame.maxY + 10
          cell.report.frame.origin.y = cell.comment.frame.maxY + 10
          cell.Likes.frame.origin.y = cell.comment.frame.maxY + 10
          cell.LikesNumber.frame.origin.y = cell.comment.frame.maxY + 10
          cell.PostView.frame.size.height =  cell.comment.frame.maxY + 50
          TableView.rowHeight = cell.PostView.frame.size.height + 20
  
          cell.CommentersName.sizeToFit()
  
          cell.pole.frame.origin.x = cell.CommentersName.frame.maxX + 5
          cell.CommentTime.frame.origin.x = cell.pole.frame.maxX + 5
  
          let numLikes = post["num_likes"] as?  NSNumber
          cell.LikesNumber.text = String(describing: numLikes!)
  
  
  
          replyId = post["id"] as? String
  
          let replyTo = post["reply_to"] as? String
          let postID = post["post_id"] as? String
  
  
  
          if replyTo == postID {
  
          } else {
              let cell = tableView.dequeueReusableCell(withIdentifier: "Reply", for: indexPath) as! RepliesTableViewCell
  
  
  
              cell.ReplyCustomCell.layer.cornerRadius = 5
              cell.ReplyCustomCell.layer.masksToBounds = false
              cell.ReplyCustomCell.layer.shadowColor = UIColor.black.withAlphaComponent(0.4).cgColor
              cell.ReplyCustomCell.layer.shadowOffset = CGSize(width: 0, height: 0)
              cell.ReplyCustomCell.layer.shadowOpacity = 0.9
  
              let post = Comments[indexPath.row] as! [String: AnyObject]
  
              cell.ReplyText.text = post["content"] as? String
              let commentname = post["author"] as? String
              cell.author.setTitle(commentname, for: .normal)
  
              if let seconds = post["pub_time"] as? Double {
                  let timeStampDate = NSDate(timeIntervalSince1970: seconds/1000)
                  let dateFormatter = DateFormatter()
                  dateFormatter.dateFormat = "MMM d, yyyy"
                  let formating = timeStampDate as Date
  
  
                  cell.time.text = dateFormatter.string(from: formating)
  
  
              }
  
              let numLikes = post["num_likes"] as?  NSNumber
              cell.num_likes.text = String(describing: numLikes!)
  
  
              textViewDidChange(cell.ReplyText)
  
              cell.ReplyText.frame.size.width = 232
              cell.ReplyText.sizeToFit()
              cell.ReplyText.clipsToBounds = true
  
              cell.author.sizeToFit()
  
              cell.pole.frame.origin.x = cell.author.frame.maxX + 5
              cell.time.frame.origin.x = cell.pole.frame.maxX + 5
  
              cell.Likes.frame.origin.y = cell.ReplyText.frame.maxY + 10
              cell.num_likes.frame.origin.y = cell.ReplyText.frame.maxY + 10
              cell.reportButton.frame.origin.y = cell.ReplyText.frame.maxY + 10
              cell.replyButton.frame.origin.y = cell.ReplyText.frame.maxY + 10
              cell.ReplyCustomCell.frame.size.height =  cell.ReplyText.frame.maxY + 50
  
               TableView.rowHeight = cell.ReplyCustomCell.frame.size.height + 20
  
              return cell
          }
  
          cell.checkfornightmode()
  
          return cell
  
      }
  </code></pre>
  
  <p>The comments that are associated with each other have the same "id", how will I organize the cells so that the comments of a main comment will be listed under the original comment. Thank you</p>