Displaying two reusable cells in tableview - Swift 3

I have two custom reusable table view cells in my table view. The first cell, I would like it to be present at all times. The second cell and beyond, are returning a count that is being passed from mysql database.




    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return posts.count
    }
  
  
   
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      
        if indexPath.row < 1 {
            let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! InfoCell
           
            return cell
     
        } else {
      
        let Postcell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! PostCell
          
            let post = posts[indexPath.row]
            let image = images[indexPath.row]
            let username = post["user_username"] as? String
            let text = post["post_text"] as? String
          
          
           
            Postcell.usernameLbl.text = username
            Postcell.textLbl.text = text
            Postcell.pictureImg.image = image
          
            return Postcell
      
        }
      
    }



My first cell is there and so are the post.count, but for some reason the posts.count is missing one post and I believe this is because of the first cell. Can anybody help me with this? thanks in advance.

Answered by QuinceyMorris in 257383022

It's an off-by-1 error. You have posts.count + 1 rows, because of the extra row at row index 0. (And you need to subtract 1 from indexPath.row throughout the "else" branch of your if.)

Accepted Answer

It's an off-by-1 error. You have posts.count + 1 rows, because of the extra row at row index 0. (And you need to subtract 1 from indexPath.row throughout the "else" branch of your if.)

Displaying two reusable cells in tableview - Swift 3
 
 
Q